Setting it makes thesqlite3 module parse the declared type for each column itreturns. It will parse out the first word of the declared type, i. e. for"integer primary key", it will parse out "integer". Then for that column, itwill look into the converters dictionary and use the converter functionregistered for that type there. Converter names are case-sensitive!
Setting this makes the SQLite interface parse the column name for each columnit returns. It will look for a string formed [mytype] in there, and thendecide that 'mytype' is the type of the column. It will try to find an entry of'mytype' in the converters dictionary and then use the converter function foundthere to return the value. The column name found incursor.description is onlythe first word of the column name, i. e. if you use something like'as "x [datetime]"' in your SQL, then we will parse out everything until thefirst blank for the column name: the column name would simply be "x".
| database[, timeout, isolation_level, detect_types, factory]) |
":memory:" to open a database connection to a database that resides inRAM instead of on disk.When a database is accessed by multiple connections, and one of the processesmodifies the database, the SQLite database is locked until that transaction iscommitted. Thetimeout parameter specifies how long the connection shouldwait for the lock to go away until raising an exception. The default for thetimeout parameter is 5.0 (five seconds).
For theisolation_level parameter, please see theisolation_levelproperty ofConnection objects in section 13.13.2.
SQLite natively supports only the types TEXT, INTEGER, FLOAT, BLOB and NULL. Ifyou want to use other types, like you have to add support for them yourself.Thedetect_types parameter and the using customconverters registered withthe module-levelregister_converter function allow you to easily do that.
detect_types defaults to 0 (i. e. off, no type detection), you can set itto any combination ofPARSE_DECLTYPES andPARSE_COLNAMES to turn typedetection on.
By default, thesqlite3 module uses itsConnection class for theconnect call. You can, however, subclass theConnection class and makeconnect use your class instead by providing your class for thefactory parameter.
Consult the section13.13.4 of this manual for details.
Thesqlite3 module internally uses a statement cache to avoid SQL parsingoverhead. If you want to explicitly set the number of statements that arecached for the connection, you can set thecached_statements parameter.The currently implemented default is to cache 100 statements.
| typename, callable) |
| type, callable) |
| sql) |
This can be used to build a shell for SQLite, as in the following example:
# A minimal SQLite shell for experimentsimport sqlite3con = sqlite3.connect(":memory:")con.isolation_level = Nonecur = con.cursor()buffer = ""print "Enter your SQL commands to execute in sqlite3."print "Enter a blank line to exit."while True: line = raw_input() if line == "": break buffer += line if sqlite3.complete_statement(buffer): try: buffer = buffer.strip() cur.execute(buffer) if buffer.lstrip().upper().startswith("SELECT"): print cur.fetchall() except sqlite3.Error, e: print "An error occurred:", e.args[0] buffer = ""con.close()| flag) |
sys.stderr. UseFalse to disablethe feature again.