Title: Theory / Unimportant / CS / Programming / Python / PEP / 249 DB
Tags: FromInstruction computer_to_instruction hasNotNewEffectReturnsMeaning some_instruction automatedNewLineAfterCommaSpace récupéré seen_description
On every note of this deck, unless a note says otherwise:
Page: https://www.python.org/dev/peps/pep-0249/
Language: Python
Page: https://www.python.org/dev/peps/pep-0249/

Instruction: DBmodule.DataError
Effect: Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range, etc. It must be a subclass of DatabaseError.

Instruction: DBmodule.OperationalError
Effect: Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer, e.g. an unexpected disconnect occurs, the data source name is not found, a transaction could not be processed, a memory allocation error occurred during processing, etc. It must be a subclass of DatabaseError.

Instruction: DBmodule.IntegrityError
Effect: Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails. It must be a subclass of DatabaseError.

Instruction: DBmodule.InternalError
Effect: Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync, etc. It must be a subclass of DatabaseError.

Instruction: DBmodule.ProgrammingError
Effect: Exception raised for programming errors, e.g. table not found or already exists, syntax error in the SQL statement, wrong number of parameters specified, etc. It must be a subclass of DatabaseError.

Instruction: DBmodule.NotSupportedError
Effect: Exception raised in case a method or database API was used which is not supported by the database, e.g. requesting a .rollback() on a connection that does not support transaction or has transactions turned off. It must be a subclass of DatabaseError.

Instruction: c.close()
Effect: Close the connection now
Variables: c a connection object

Question: What happen when c is deleted.
Answer: the collection is closed
Variables: c a connection object

Question: What happen when something is called on c after it is closed ?
Answer: An error or subclass will be raised.
Variables: c a connection object

Question: What happen when something is called on a cursor from c after it is closed ?
Answer: An error or subclass will be raised.
Variables: c a connection object

Instruction: c.commit()
Effect: Commit any pending transaction to the database.
Variables: c a connection object

Question: What happen if a db is closed without being committed ?
Answer: Rollback is performed first
Variables: c a connection object

Question: What is commit in a database without transaction ?
Answer: Void function
Variables: c a connection object

Instruction: c.rollback()
Effect: Causes the database to roll back to the start of any pending transaction.
Variables: c a connection object

Instruction: c.cursor()
Returns: A new Cursor Object using the connection.
Variables: c a connection object

Question: What happens if .cursor() is called on a data base on which the notion of cursor is not defined ?
Answer: It must be emuled by the library
Variables: c a connection object

Instruction: cu.description
Effect: This read-only attribute is a sequence of 7-item sequences.
Each of these sequences contains information describing one result column:
name
type_code
display_size
internal_size
precision
scale
null_ok
Variables: co a connection object
cu a cursor on co

Instruction: cu.rowcount
Effect: This read-only attribute specifies the number of rows that the last .execute*() produced (for DQL statements like SELECT) or affected (for DML statements like UPDATE or INSERT).
Variables: co a connection object
cu a cursor on co

Instruction: cu.callproc(
  foo,
  params
)
Effect: Call a stored database procedure with the given name. The sequence of parameters must contain one entry for each argument that the procedure expects. The result of the call is returned as modified copy of the input sequence. Input parameters are left untouched, output and input/output parameters replaced with possibly new values.
The procedure may also provide a result set as output. This must then be made available through the standard .fetch*() methods.
Variables: co a connection objectcu a cursor on co

Question: What happen when something is called on cu after it is closed ?
Answer: An error or subclass will be raised.
Variables: co a connection object
cu a cursor on co

Instruction: cu.close()
Effect: Close the cursor now
Variables: co a connection object
cu a cursor on co

Question: What happen when cu is deleted.
Answer: the cursor is closed
Variables: co a connection object
cu a cursor on co

Instruction: cu.execute(
  operation,
  params
)
Effect: Prepare and execute a database operation (query or command).
Parameters may be provided as sequence or mapping and will be bound to variables in the operation. Variables are specified in a database-specific notation
Variables: co a connection object
cu a cursor on co

Instruction: cu.executemany(
  operation,
  params
)
Effect: Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters.
Variables: co a connection object
cu a cursor on co
Assuming: No result set is returned by the operation

Instruction: cu.fetchone()
Effect: Fetch the next row of a query result set, returning a single sequence, or None when no more data is available.
Variables: co a connection object
cu a cursor on co
Assuming: Last execute* exists and did produce a result set

Instruction: cu.fetchmany()
Effect: Fetch the next set of rows of a query result, returning a sequence of sequences (e.g. a list of tuples). An empty sequence is returned when no more rows are available.
The number of rows to fetch per call is specified by the parameter. If it is not given, the cursor's arraysize determines the number of rows to be fetched. The method should try to fetch as many rows as indicated by the size parameter. If this is not possible due to the specified number of rows not being available, fewer rows may be returned.
Variables: co a connection object
cu a cursor on co
Assuming: Last execute* exists and did produce a result set

Instruction: cu.fetchall()
Effect: Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples). Note that the cursor's arraysize attribute can affect the performance of this operation.
Variables: co a connection object
cu a cursor on co
Assuming: Last execute* exists and did produce a result set

Instruction: cu.nextset()
Effect: This method will make the cursor skip to the next available set, discarding any remaining rows from the current set. Subsequent calls to the .fetch*() methods will return rows from the next result set if it exists
Returns: Whether there are more sets (i.e. fetch can be called)
Variables: co a connection object
cu a cursor on co
Assuming: Last execute* exists and did produce a result set

Instruction: cu.arraysize
Effect: This read/write attribute specifies the number of rows to fetch at a time with .fetchmany(). It defaults to 1 meaning to fetch a single row at a time.
Variables: co a connection object
cu a cursor on co

Instruction: cu.setinputsize(sizes)
Effect: This can be used before a call to .execute*() to predefine memory areas for the operation's parameters.
Variables: co a connection object
cu a cursor on co
Assuming: sizes is specified as a sequence — one item for each input parameter. The item should be a Type Object that corresponds to the input that will be used, or it should be an integer specifying the maximum length of a string parameter. If the item is None, then no predefined memory area will be reserved for that column (this is useful to avoid predefined areas for large inputs)

Instruction: cu.setoutputsize(sizes)
Effect: Set a column buffer size for fetches of large columns (e.g. LONGs, BLOBs, etc.). The column is specified as an index into the result sequence. Not specifying the column will set the default size for all large columns in the cursor.
Variables: co a connection object
cu a cursor on co
Assuming: Sizes is specified as a sequence — one item for each input parameter. The item should be a Type Object that corresponds to the input that will be used, or it should be an integer specifying the maximum length of a string parameter. If the item is None, then no predefined memory area will be reserved for that column (this is useful to avoid predefined areas for large inputs).

Question: What should be done to ensure that a database type (e.g. time) is treated correctly in query ?
Answer: Use a constructor, such as Time(), and pass its result in the query constructor
Variables: co a connection object
cu a cursor on co

Instruction: DBModule.connect(paramaters)
Returns: A Connection object for a database, according to parameters

Instruction: DBModule.apilevel
Effect: The supported DB API level of this module

Instruction: DBmodule.threadsafety
Effect: An int i such that threads may share the i first elements of [module, connections, cursors]

Instruction: DBmodule.paramstyle
Effect: A string indicating of this database module want parameters. Eg ? :1 :name %s %(name)s

Instruction: DBmodule.Warning
Effect: Exception raised for important warnings like data truncations while inserting, etc. It must be a subclass of the Python StandardError (defined in the module exceptions).

Instruction: DBmodule.Error
Effect: Exception that is the base class of all other error exceptions. You can use this to catch all errors with one single except statement. Warnings are not considered errors and thus should not use this class as base. It must be a subclass of the Python StandardError (defined in the module exceptions).

Instruction: DBmodule.interfaceError
Effect: Exception raised for errors that are related to the database interface rather than the database itself. It must be a subclass of Error.

Instruction: DBmodule.DatabaseError
Effect: Exception raised for errors that are related to the database. It must be a subclass of Error.