python-Simple sqlite3 Use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.