33 lines
1.1 KiB
Rexx
33 lines
1.1 KiB
Rexx
/* 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' |