1 #Import SQLite driver:2>>>ImportSqlite33 #Connect to the SQLite database4 #The database file is test.db5 #If the file does not exist, it is automatically created in the current directory:6>>> conn = Sqlite3.connect ('test.db')7 #Create a cursor:8>>> cursor =conn.cursor ()9 #execute an SQL statement to create the user table:Ten>>> Cursor.execute ('CREATE TABLE User (ID varchar () primary key, name varchar )') One<sqlite3. Cursor Object at 0x10f8aa260> A #continue executing an SQL statement and insert a record: ->>> Cursor.execute ('INSERT into user (ID, name) VALUES (\ ' 1\ ', \ ' michael\ ')') -<sqlite3. Cursor Object at 0x10f8aa260> the #to get the number of rows inserted through ROWCOUNT: ->>>Cursor.rowcount -1 - #Close cursor: +>>>cursor.close () - #COMMIT TRANSACTION: +>>>Conn.commit () A #Close connection: at>>>conn.close () - - - ->>> conn = Sqlite3.connect ('test.db') ->>> cursor =conn.cursor () in #To execute a query statement: ->>> Cursor.execute ('SELECT * from user where id=?', ('1',)) to<sqlite3. Cursor Object at 0x10f8aa340> + #To obtain a query result set: ->>> values =Cursor.fetchall () the>>>Values *[('1','Michael')] $>>>cursor.close ()Panax Notoginseng>>> Conn.close ()
python-Simple sqlite3 Use