HTML Image
Forum: 1 Lucky Nerd

  • SQLite for Synchronet

    From nelgin@1:103/705 to All on Monday, May 05, 2025 11:38:53
    Hi all,

    With much help from Digital Man, I have added the abilty use SQLite databases through JavaScript within Synchronet. It's a work in progress and always happy to accept patches and the like.

    It's not been merged yet and will only work on Linux so far, You'll need to checkout the sqlite branch and make sure you have libsqlite3 installed.

    // open a new database object. This will create the database if it doesn't
    // exist
    var db = new Sqlite("/tmp/base1");
    if (!db.open())
    writeln ("Unable to open database: " + db.errormsg);

    // Create a table for our data
    if (db.exec("CREATE TABLE test (firstname text , lastname text)"))
    writeln ("Table created");
    else
    writeln ("Unable to create table: " + db.errormsg);

    // insert a row into the database
    if (db.exec("INSERT INTO test VALUES ('Fred','Smith'),('Joe','Bloggs'),('Jimmy','Jones')"))
    writeln ("Row inserted");
    else
    writeln ("Unable to insert row" + db.errormsg);

    // Query the database and print results
    var ret;
    var row;
    if (ret = db.exec("SELECT firstname,lastname FROM test")) {
    for (row in ret) {
    writeln (ret[row].firstname + " " + ret[row].lastname);
    }
    }
    else {
    writeln ("Unable to fetch rows" + db.errormsg);
    }

    // close the database
    db.close();


    This may need futher work to be able to use PREPAREd statements and the like but your basic SQL functions are going to work. Right now it's up to the user to properly encode the text to UTF-8 and escape any values but this will be added later, I'm sure, by someone more knowledgable than me.

    ---
    þ Synchronet þ End Of The Line BBS - endofthelinebbs.com
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Ragnarok@1:103/705 to All on Monday, May 05, 2025 14:55:36
    El 5/5/25 a las 13:38, nelgin (VERT/EOTLBBS) escribió:
    Hi all,

    With much help from Digital Man, I have added the abilty use SQLite databases through JavaScript within Synchronet. It's a work in progress and always happy to accept patches and the like.

    It's not been merged yet and will only work on Linux so far, You'll need to checkout the sqlite branch and make sure you have libsqlite3 installed.

    // open a new database object. This will create the database if it doesn't
    // exist
    var db = new Sqlite("/tmp/base1");
    if (!db.open())
    writeln ("Unable to open database: " + db.errormsg);

    // Create a table for our data
    if (db.exec("CREATE TABLE test (firstname text , lastname text)"))
    writeln ("Table created");
    else
    writeln ("Unable to create table: " + db.errormsg);

    great very nice!
    ---
    ï¿­ Synchronet ï¿­ Dock Sud BBS TLD 24 HS - bbs.docksud.com.ar
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From nelgin@1:103/705 to Ragnarok on Monday, May 05, 2025 14:20:25
    Re: Re: SQLite for Synchronet
    By: Ragnarok to All on Mon May 05 2025 14:55:36

    great very nice!

    Thanks. I tried leaving a message for you in a few places and never heard back. Since this was your code originally, you may want to take a look and see if there are any improvements.

    One question we do have is why can you set db.stmt or provide a parameter as part of db.exec() ?

    ---
    þ Synchronet þ End Of The Line BBS - endofthelinebbs.com
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)

I recommend using



to connect to the BBS