[SCM] Lisaac library examples branch, master, updated. 000d4746fdfc94fd51761922e30f810bf0afeb68
Jeremy (none)
jeremy at jeremy-desktop.
Tue Nov 11 01:31:30 UTC 2008
The following commit has been merged in the master branch:
commit 000d4746fdfc94fd51761922e30f810bf0afeb68
Author: Jeremy <jeremy at jeremy-desktop.(none)>
Date: Mon Nov 10 20:31:22 2008 -0500
Added example for sqlite binding
diff --git a/sqlite_test/example1.li b/sqlite_test/example1.li
new file mode 100644
index 0000000..c74ccda
--- /dev/null
+++ b/sqlite_test/example1.li
@@ -0,0 +1,71 @@
+Section Header
+ + name := EXAMPLE1;
+
+Section Public
+ - main <-
+ (
+ + d:SQLITE;
+ + s:SQLITE_STATEMENT;
+
+ "Opening database example.db\n".print;
+ d := SQLITE.open("example.db");
+
+ d.is_empty.if {
+ "Creating our names table\n".print;
+ ( d.exec ("CREATE TABLE names (id INTEGER, name VARCHAR(20))") != SQLITE.ok ).if {
+ "Could not create new names table!\n".print;
+ OBJECT.die_with_code 1;
+ };
+ };
+
+ ( COMMAND_LINE.upper > 1 ).if {
+ "Inserting new names from the command line\n".print;
+ s := d.prepare("INSERT INTO names VALUES (?,?)");
+ 1.to (COMMAND_LINE.upper) do { i:INTEGER;
+ s.bind 1 to_integer i;
+ s.bind 2 to_string (COMMAND_LINE.item i);
+ ( s.step != SQLITE.done ).if {
+ ( "Error inserting new record: " + d.errmsg + "\n").print;
+ OBJECT.die_with_code 1;
+ };
+ (" Inserted: " + (COMMAND_LINE.item i) + "\n").print;
+ s.reset;
+ };
+ s.finalize;
+ };
+
+ "Querying all records from the names table\n".print;
+
+ /*
+ s := d.prepare("SELECT * FROM names");
+ { s.step = SQLITE.row }.while_do {
+ ( s.as_string 0 + " " + s.as_string 1 + "\n").print;
+ };
+ s.finalize;
+ */
+
+ /*
+ s := d.prepare("SELECT * FROM names");
+ s.foreach {
+ ( s.as_string 0 + " " + s.as_string 1 + "\n").print;
+ };
+ s.finalize;
+ */
+
+ d.foreach "SELECT * FROM names" do { row:SQLITE_STATEMENT;
+ ( " " + row.as_string 0 + " " + row.as_string 1 + "\n").print;
+ } else {
+ " No results found...\n".print;
+ " use ./example Name1 Name2 Name3 to add some\n".print;
+ };
+
+ "Querying all records with id > 10 from the names table\n".print;
+ d.foreach "SELECT * FROM names WHERE id > 10" do { row:SQLITE_STATEMENT;
+ ( " " + row.as_string 0 + " " + row.as_string 1 + "\n").print;
+ } else {
+ " No results found for id > 10\n".print;
+ };
+
+ "Closing database\n".print;
+ d.close;
+ );
--
Lisaac library examples
More information about the Lisaac-commits
mailing list