Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,41 @@
|
|||
import Database as db;
|
||||
import Algorithms as algo;
|
||||
import FileSystem as fs;
|
||||
|
||||
main() {
|
||||
dbPath = "/tmp/parametrized-sql.sqlite";
|
||||
fs.remove( dbPath );
|
||||
fs.open( dbPath, fs.OPEN_MODE.WRITE );
|
||||
conn = db.connect( "sqlite3:///" + dbPath );
|
||||
|
||||
// Setup...
|
||||
conn.query(
|
||||
"CREATE TABLE Players (\n"
|
||||
"\tname VARCHAR(64),\n"
|
||||
"\tscore FLOAT,\n"
|
||||
"\tactive INTEGER,\n"
|
||||
"\tno VARCHAR(8)\n"
|
||||
");"
|
||||
).execute();
|
||||
conn.query(
|
||||
"INSERT INTO Players VALUES ( 'name', 0, 'false', 99 );"
|
||||
).execute();
|
||||
conn.query(
|
||||
"INSERT INTO Players VALUES ( 'name', 0, 'false', 100 );"
|
||||
).execute();
|
||||
|
||||
// Demonstrate parameterized SQL...
|
||||
parametrizedQuery = conn.query(
|
||||
"UPDATE Players SET name=?, score=?, active=? WHERE no=?"
|
||||
);
|
||||
for ( i, v : algo.enumerate( ( "Smith, Steve", 42, true, 99 ) ) ) {
|
||||
parametrizedQuery.bind( i + 1, string( v ) );
|
||||
}
|
||||
parametrizedQuery.execute();
|
||||
|
||||
// and show the results...
|
||||
for ( record : conn.query( "SELECT * FROM Players;" ).execute() ) {
|
||||
print( "{}\n".format( record ) );
|
||||
}
|
||||
return ( 0 );
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue