![]() ![]() ![]() execute ( """ create table if not exists obj2 ( id integer primary key autoincrement not null, data text ) """ ) cursor = conn. PARSE_COLNAMES ) as conn : # Create a table with column of type "text" conn. connect ( db_filename, detect_types = sqlite3. Use a list of tuples so we # can pass this sequence directly to executemany(). register_converter ( "MyObj", converter_func ) # Create some objects to save. register_adapter ( MyObj, adapter_func ) sqlite3. arg ) # Register the functions for manipulating the type. fetchone () print ( 'Project details for )'. execute ( """ select name, description, deadline from project where name = 'pymotw' """ ) name, description, deadline = cursor. connect ( db_filename ) as conn : # Change the row factory to use Row conn. Import sqlite3 db_filename = 'todo.db' with sqlite3. The sqlite3Ĭommand line program can be used to examine the contents of the executescript ( """ insert into project (name, description, deadline) values ('pymotw', 'Python Module of the Week', '') insert into task (details, status, deadline, project) values ('write about select', 'done', '', 'pymotw') insert into task (details, status, deadline, project) values ('write about random', 'waiting', '', 'pymotw') insert into task (details, status, deadline, project) values ('write about sqlite3', 'active', '', 'pymotw') """ ) else : print ( 'Database exists, assume schema does, too.' )Īfter the tables are created, a few insert statementsĬreate a sample project and related tasks. executescript ( schema ) print ( 'Inserting initial data' ) conn. connect ( db_filename ) as conn : if db_is_new : print ( 'Creating schema' ) with open ( schema_filename, 'rt' ) as f : schema = f. Import os import sqlite3 db_filename = 'todo.db' schema_filename = 'todo_schema.sql' db_is_new = not os. The data definition language (DDL) statements to create the tables Task status (one of ‘new’, ‘pending’, ‘done’, or ‘canceled’). Numerical priority, lower is more important The details of the database schema are presented The remainingĮxamples in this section all use the same database schema with tablesįor managing tasks. Schema to define the tables within the database. ![]() Database exists, assume schema does, too.Īfter creating the new database file, the next step is to create the ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |