add sqlite example
This commit is contained in:
parent
dc697b6c4e
commit
82793173a0
33
projects/oorexx/oosqlite3-test.rex
Normal file
33
projects/oorexx/oosqlite3-test.rex
Normal file
@ -0,0 +1,33 @@
|
||||
/* Rexx SQLite3 Demo */
|
||||
|
||||
db = .ooSQLiteConnection~new(":memory:",.ooSQLite~OPEN_READWRITE)
|
||||
|
||||
db~exec("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)")
|
||||
db~exec("INSERT INTO users (name, age)",
|
||||
"VALUES ('Alice', 30), ('Albert', 24), ('Allen', 50), ('Andrew', 42), ('Anne', 29);")
|
||||
|
||||
results1 = db~exec("SELECT * FROM users",.true,.ooSQLite~OO_ARRAY_OF_ARRAYS)
|
||||
results2 = db~exec("SELECT * FROM users",.true,.ooSQLite~OO_ARRAY_OF_DIRECTORIES)
|
||||
|
||||
/* Array of Arrays */
|
||||
DO counter i row over results1
|
||||
if i > 1 then DO /* first row is the header (indexes) array */
|
||||
say results1[1][1]"="row[1]", "results1[1][2]"="row[2]", "results1[1][3]"="row[3]
|
||||
END
|
||||
END
|
||||
|
||||
/* Array of 'Directories' (what Rexx calls a Dictionary) */
|
||||
DO dir over results2
|
||||
/* The following is the equivalent of python mydict.keys() and mydict.items() methods:*/
|
||||
/* say dir~AllIndexes; say dir~AllItems */
|
||||
/* keys are rendered as attributes on the instance object: */
|
||||
say dir~Id". "dir~Name", "dir~Age
|
||||
/* OR: you can access the keys directly, in upper-case: */
|
||||
say dir["ID"]". "dir["NAME"]", "dir["AGE"]
|
||||
END
|
||||
|
||||
db~close
|
||||
|
||||
EXIT
|
||||
|
||||
::requires 'ooSQLite.cls'
|
Loading…
Reference in New Issue
Block a user