[SCM] Lisaac library examples branch, master, updated. d7b3af6efc02eecc8a625af8bcb4d7cebf916f18

Jeremy Cowgar jeremy at cowgar.com
Tue Nov 11 04:51:10 UTC 2008


The following commit has been merged in the master branch:
commit d7b3af6efc02eecc8a625af8bcb4d7cebf916f18
Author: Jeremy Cowgar <jeremy at cowgar.com>
Date:   Mon Nov 10 23:50:20 2008 -0500

    * Made use of new field_as_* methods
    * Formatted code a bit better
    * Changed filtered example to be < 3 which will occur more often
      in the example app vs. > 10.

diff --git a/sqlite_test/example1.li b/sqlite_test/example1.li
index c74ccda..87fd432 100644
--- a/sqlite_test/example1.li
+++ b/sqlite_test/example1.li
@@ -12,7 +12,9 @@ Section Public
 
 		d.is_empty.if {
 			"Creating our names table\n".print;
-			( d.exec ("CREATE TABLE names (id INTEGER, name VARCHAR(20))") != SQLITE.ok ).if {
+			( d.exec ("CREATE TABLE names (id INTEGER PRIMARY KEY AUTOINCREMENT, \
+				\ name VARCHAR(20))") != SQLITE.ok
+			).if {
 				"Could not create new names table!\n".print;
 				OBJECT.die_with_code 1;
 			};
@@ -20,10 +22,9 @@ Section Public
 
 		( COMMAND_LINE.upper > 1 ).if {
 			"Inserting new names from the command line\n".print;
-			s := d.prepare("INSERT INTO names VALUES (?,?)");
+			s := d.prepare("INSERT INTO names (name) 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.bind 1 to_string (COMMAND_LINE.item i);
 				( s.step != SQLITE.done ).if {
 					( "Error inserting new record: " + d.errmsg + "\n").print;
 					OBJECT.die_with_code 1;
@@ -53,17 +54,18 @@ Section Public
 		*/
 
 		d.foreach "SELECT * FROM names" do { row:SQLITE_STATEMENT;
-			( "   " + row.as_string 0 + " " + row.as_string 1 + "\n").print;
+			( "   " + row.field_as_string "id" + " " +
+				row.field_as_string "name" + "\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;
+		"Querying all records with id < 3 from the names table\n".print;
+		d.foreach "SELECT * FROM names WHERE id < 3" do { row:SQLITE_STATEMENT;
 			( "   " + row.as_string 0 + " " + row.as_string 1 + "\n").print;
 		} else {
-			"   No results found for id > 10\n".print;
+			"   No results found for id < 3\n".print;
 		};
 
 		"Closing database\n".print;

-- 
Lisaac library examples



More information about the Lisaac-commits mailing list