• database object

    From Ragnarok@VERT/DOCKSUD to DOVE-Net.Sync_JavaScript on Mon Apr 9 00:32:00 2007
    Hi people
    i try to add a database support the the js script in syncrhonet
    i use (at moment) sqlite as backend.

    i thinking in an object that may be used to easy storage data for door or modules and easy access via sql standard commands.
    an simple example of script code :

    db = new Sqlite("/tmp/tu_base.db");
    db.open();
    db.stmt = "CREATE TABLE prueba (field1 int , field2 varchar(100))";
    db.exec();
    db.stmt = "INSERT INTO prueba (field1,field2) VALUES (10,'hola')";
    db.exec();
    db.stmt = "SELECT * FROM prueba";
    db.exec();
    for(i=; i< db.numRows; i++) {
    writeln (db.result[i]['field1'] + '-' + db.result[i]['field2']);
    }
    db.close();

    im still working and not yet complete, also i dont know if will add to the futures sync versions.

    you can see source code and example here: http://bbs.docksud.com.ar/~ragnarok/sync/js_sqlite/

    i wait for comments, suggest or wahtever for people that make js scripts.

    Saludos!


    --
    Dock Sud BBS
    http://bbs.docksud.com.ar
    telnet://bbs.docksud.com.ar

    ---
    þ Synchronet þ Dock Sud BBS TLD 24 HS - www.docksud.com.ar
  • From Digital Man@VERT to Ragnarok on Mon Apr 9 22:38:41 2007
    Re: database object
    By: Ragnarok to DOVE-Net.Sync_JavaScript on Sun Apr 08 2007 05:32 pm

    Hi people
    i try to add a database support the the js script in syncrhonet
    i use (at moment) sqlite as backend.

    i thinking in an object that may be used to easy storage data for door or modules and easy access via sql standard commands.
    an simple example of script code :

    db = new Sqlite("/tmp/tu_base.db");
    db.open();
    db.stmt = "CREATE TABLE prueba (field1 int , field2 varchar(100))"; db.exec();

    Why not just db.exec("CREATE TABLE prueba (field1 int , field2 varchar(100))") ?

    digital man (xbox-live: digitlman)

    Snapple "Real Fact" #161:
    The first TV network kids show in the U.S. was "Captain Kangaroo."
    Norco, CA WX: 88.3øF, 31% humidity, 4 mph SSE wind, 0.00 inches rain/24hrs

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Ragnarok@VERT/DOCKSUD to Digital Man on Tue Apr 10 06:33:00 2007
    Digital Man wrote:

    Re: database object
    By: Ragnarok to DOVE-Net.Sync_JavaScript on Sun Apr 08 2007 05:32 pm

    Hi people
    i try to add a database support the the js script in syncrhonet
    i use (at moment) sqlite as backend.

    i thinking in an object that may be used to easy storage data for door
    or modules and easy access via sql standard commands.
    an simple example of script code :

    db = new Sqlite("/tmp/tu_base.db");
    db.open();
    db.stmt = "CREATE TABLE prueba (field1 int , field2 varchar(100))"; db.exec();

    Why not just db.exec("CREATE TABLE prueba (field1 int , field2 varchar(100))") ?


    now, it work as exec(query) too.


    --
    Dock Sud BBS
    http://bbs.docksud.com.ar
    telnet://bbs.docksud.com.ar

    ---
    þ Synchronet þ Dock Sud BBS TLD 24 HS - www.docksud.com.ar
  • From Tracker1@VERT/TRN to Ragnarok on Tue Apr 10 18:34:00 2007
    Ragnarok wrote:
    db = new Sqlite("/tmp/tu_base.db");
    db.open();
    db.stmt = "CREATE TABLE prueba (field1 int , field2 varchar(100))";
    db.exec();

    Why not just db.exec("CREATE TABLE prueba (field1 int , field2
    varchar(100))") ?

    now, it work as exec(query) too.

    Suggestion for syntax...

    var db = new Sqlite("/tmp/tu_base.db");
    try {
    db.open(); //throw an object when a connection fails...
    var results = db.exec("CREATE TABLE ...");
    //should return 0, no rows effected

    results = db.query("SELECT ...");
    results.rows <-- array of rows
    results.columns <-- array of column titles
    for (i in results.rows) {
    results.rows[i]["columnName"]
    ...or...
    results.rows[i][columnIndex]
    }
    } catch(dbError) {
    console.write("ERROR: " + dbError.message + "\r\n\r\n");
    }

    Just a suggestion on this, to keep it easy enough to use the results...
    a .exec() method which executes the query and returns the rows affected as the result... a .query() method which returns a results object that has a rows array defined (each row containing an associative array for columns, in order)... as well as a columns array listing the column names.. results.rows.length could be used to determin a result count.

    Have a DatabaseErrorObject that is thrown when an error state occurs, with a .toString() and .Message properties for use in a result message.

    --
    Michael J. Ryan - tracker1(at)theroughnecks(dot)net - www.theroughnecks.net icq: 4935386 - AIM/AOL: azTracker1 - Y!: azTracker1 - MSN/Win: (email)

    ---
    þ Synchronet þ theroughnecks.net - you know you want it