• Inital commit of sqlite support.

    From MRO@VERT/BBSESINF to Fernando Toledo on Friday, May 09, 2025 11:19:06
    Re: Inital commit of sqlite support.
    By: Fernando Toledo to GitLab note in main/sbbs on Fri May 09 2025 07:07 am

    No, my English is pretty bad, this is a assisted translation, ha!


    oh come on, you speak better english than me or a lot of english speaking people. btw, trump is changing the termonology to 'American'.
    ---
    þ Synchronet þ ::: BBSES.info - free BBS services :::
  • From Nigel Reed@VERT to GitLab note in main/sbbs on Friday, May 09, 2025 16:36:06
    https://gitlab.synchro.net/main/sbbs/-/merge_requests/538#note_7224

    This doesn't demonstrate how to do a prepare though.

    For example, in perl, we'd do something like

    ```
    my $dbh = DBI->connect("dbi:SQLite:dbname=/sbbs/data/mydatabase.db", "", "", {
    RaiseError => 1,
    AutoCommit => 1,
    }) or die $DBI::errstr;
    my $try = $dbh->prepare("UPDATE queue SET retry=retry+1 WHERE site=?");
    my $reset = $dbh->do("UPDATE queue SET retry=0");
    my $comp = $dbh->prepare("UPDATE queue SET complete=1 WHERE site=?");


    $try->execute("endofthelinebbs.com");
    $comp->execute("vert.synchro.net");
    $reset->execute();
    ```

    So db.query would be the same as $dbh->do

    So do we need to create db.prepare ?

    I'm really not sure where to go with this.

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Fernando Toledo@VERT to GitLab note in main/sbbs on Saturday, May 10, 2025 07:58:02
    https://gitlab.synchro.net/main/sbbs/-/merge_requests/538#note_7225

    What I'm trying to say is that from JavaScript, just use exec() or query() as needed, without needing to do a prepare.

    Because the prepare is done directly within the C code.

    So both methods in JS receive the string with the SQL as parameters.
    The difference is that exec() can return true/false (or the number of rows affected) and query() can return an array of result rows.

    Each method must be implemented in the C code, for example.

    ```c++
    static JSBool
    js_sqlite_exec(JSContext *cx, uintN argc, jsval *arglist)
    {
    JSObject *obj = JS_THIS_OBJECT(cx, arglist);
    jsval *argv = JS_ARGV(cx, arglist);
    char *sql;
    sqlite3 *db;
    char *errmsg = NULL;
    int rc;

    if (!JS_ConvertArguments(cx, argc, argv, "s", &sql))
    return JS_FALSE;

    // Obtener la conexi¢n a la base de datos desde el objeto JavaScript
    db = JS_GetPrivate(cx, obj);
    if (!db)
    return JS_FALSE;

    rc = sqlite3_exec(db, sql, NULL, NULL, &errmsg);
    if (rc != SQLITE_OK) {
    JS_ReportError(cx, "Error al ejecutar SQL: %s", errmsg);
    sqlite3_free(errmsg);
    return JS_FALSE;
    }

    JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
    return JS_TRUE;
    }
    ```
    and query method

    ```c++
    static JSBool
    js_sqlite_query(JSContext *cx, uintN argc, jsval *arglist)
    {
    JSObject *obj = JS_THIS_OBJECT(cx, arglist);
    jsval *argv = JS_ARGV(cx, arglist);
    char *sql;
    sqlite3 *db;
    sqlite3_stmt *stmt;
    int rc;

    if (!JS_ConvertArguments(cx, argc, argv, "s", &sql))
    return JS_FALSE;

    // Obtener la conexi¢n a la base de datos desde el objeto JavaScript
    db = JS_GetPrivate(cx, obj);
    if (!db)
    return JS_FALSE;

    rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
    if (rc != SQLITE_OK) {
    JS_ReportError(cx, "Error al preparar la consulta: %s", sqlite3_errmsg(db));
    return JS_FALSE;
    }

    JSObject *resultArray = JS_NewArrayObject(cx, 0, NULL);
    int index = 0;

    while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
    int colCount = sqlite3_column_count(stmt);
    JSObject *rowObj = JS_NewObject(cx, NULL, NULL, NULL);

    for (int i = 0; i < colCount; i++) {
    const char *colName = sqlite3_column_name(stmt, i);
    const char *colValue = (const char *)sqlite3_column_text(stmt, i);
    jsval val = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, colValue ? colValue : ""));
    JS_SetProperty(cx, rowObj, colName, &val);
    }

    jsval rowVal = OBJECT_TO_JSVAL(rowObj);
    JS_SetElement(cx, resultArray, index++, &rowVal);
    }

    sqlite3_finalize(stmt);

    if (rc != SQLITE_DONE) {
    JS_ReportError(cx, "Error al ejecutar la consulta: %s", sqlite3_errmsg(db));
    return JS_FALSE;
    }

    JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(resultArray));
    return JS_TRUE;
    }
    ```

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Fernando Toledo@VERT to GitLab note in main/sbbs on Saturday, May 10, 2025 11:05:52
    https://gitlab.synchro.net/main/sbbs/-/merge_requests/538#note_7226

    Hello! Please check this commit at my sqlite branch

    https://gitlab.synchro.net/Ragnarok/sbbs/-/commit/2e7de43846adfe741b5b55f3b8e20e3feae05da6

    here is a test example to use (notice that stmt is not use anymore here)

    ```javsacript
    var ret; //return object array
    var row; //row object

    db = new Sqlite("/tmp/base1");
    db.debug = true;
    if (!db.open())
    writeln ("i cant open it: " + db.errormsg);

    if(db.exec("create table test (a int , b text)"))
    writeln ("OK Create");
    else
    writeln ("ops " + db.errormsg);

    for (i=1;i<10;i++)
    if(db.exec("insert into test values (" + i + ",'hola')"))
    writeln ("OK inserted ");
    else
    writeln ("ops " + db.errormsg);

    writeln ("queryng data:");

    if (ret = db.query("select a,b from test")) {
    for (row in ret) {
    writeln (ret[row].a + " " + ret[row].b);
    }
    }
    else {
    writeln ("ops: " + db.errormsg);
    }

    writeln ("deleting data:");

    if (ret = db.exec("delete from test")) {
    writeln("OK delete");
    }
    else {
    writeln ("ops: " + db.errormsg);
    }

    db.close();

    ```

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Fernando Toledo@VERT to GitLab note in main/sbbs on Saturday, May 10, 2025 11:06:03
    https://gitlab.synchro.net/main/sbbs/-/merge_requests/538#note_7226

    Hello! Please check this commit at my sqlite branch

    https://gitlab.synchro.net/Ragnarok/sbbs/-/commit/2e7de43846adfe741b5b55f3b8e20e3feae05da6

    here is a test example to use (notice that stmt is not use anymore here)

    ```javascript
    var ret; //return object array
    var row; //row object

    db = new Sqlite("/tmp/base1");
    db.debug = true;
    if (!db.open())
    writeln ("i cant open it: " + db.errormsg);

    if(db.exec("create table test (a int , b text)"))
    writeln ("OK Create");
    else
    writeln ("ops " + db.errormsg);

    for (i=1;i<10;i++)
    if(db.exec("insert into test values (" + i + ",'hola')"))
    writeln ("OK inserted ");
    else
    writeln ("ops " + db.errormsg);

    writeln ("queryng data:");

    if (ret = db.query("select a,b from test")) {
    for (row in ret) {
    writeln (ret[row].a + " " + ret[row].b);
    }
    }
    else {
    writeln ("ops: " + db.errormsg);
    }

    writeln ("deleting data:");

    if (ret = db.exec("delete from test")) {
    writeln("OK delete");
    }
    else {
    writeln ("ops: " + db.errormsg);
    }

    db.close();

    ```

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Fernando Toledo@VERT to GitLab note in main/sbbs on Saturday, May 10, 2025 11:07:29
    https://gitlab.synchro.net/main/sbbs/-/merge_requests/538#note_7226

    Hello! Please check this commit at my sqlite branch

    https://gitlab.synchro.net/Ragnarok/sbbs/-/commit/2e7de43846adfe741b5b55f3b8e20e3feae05da6

    It probably still needs better validations and verifications, but that's the idea I was trying to tell you.

    Here is a js test example to use (notice that stmt is not use anymore here)

    ```javascript
    var ret; //return object array
    var row; //row object

    db = new Sqlite("/tmp/base1");
    db.debug = true;
    if (!db.open())
    writeln ("i cant open it: " + db.errormsg);

    if(db.exec("create table test (a int , b text)"))
    writeln ("OK Create");
    else
    writeln ("ops " + db.errormsg);

    for (i=1;i<10;i++)
    if(db.exec("insert into test values (" + i + ",'hola')"))
    writeln ("OK inserted ");
    else
    writeln ("ops " + db.errormsg);

    writeln ("queryng data:");

    if (ret = db.query("select a,b from test")) {
    for (row in ret) {
    writeln (ret[row].a + " " + ret[row].b);
    }
    }
    else {
    writeln ("ops: " + db.errormsg);
    }

    writeln ("deleting data:");

    if (ret = db.exec("delete from test")) {
    writeln("OK delete");
    }
    else {
    writeln ("ops: " + db.errormsg);
    }

    db.close();

    ```

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Fernando Toledo@VERT to GitLab note in main/sbbs on Saturday, May 10, 2025 11:09:09
    https://gitlab.synchro.net/main/sbbs/-/merge_requests/538#note_7228

    Using exec() for insert/update/delete queries should be a little more optimal than query()

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Rob Swindell@VERT to GitLab note in main/sbbs on Saturday, May 10, 2025 15:30:47
    https://gitlab.synchro.net/main/sbbs/-/merge_requests/538#note_7231

    if 'stmt' is always passed as an argument to the methods, there's no need store it ('stmt' member) in the private structure and then have to worry about freeing it in the finalizer.

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Nigel Reed@VERT to GitLab note in main/sbbs on Thursday, July 31, 2025 23:25:14
    https://gitlab.synchro.net/main/sbbs/-/merge_requests/538#note_7454

    How are we doing on this?

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Rob Swindell@VERT to GitLab note in main/sbbs on Friday, August 01, 2025 11:34:05
    https://gitlab.synchro.net/main/sbbs/-/merge_requests/538#note_7455

    Who is 'we'? I didn't merge it because Deuce has strong security concerns about this implementation. I guess he already shared those concerns (with you?) in IRC. I was hoping he'd detail those concerns in comments here as well, but maybe someone can dig up the IRC log and just paste it here.

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Nigel Reed@VERT to GitLab note in main/sbbs on Friday, August 01, 2025 12:15:17
    https://gitlab.synchro.net/main/sbbs/-/merge_requests/538#note_7456

    We as in the collective who has worked on it.

    I don't recall that conversation with Deuce but that doesn't mean it didn't happen. I can check my logs later.

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Nigel Reed@VERT to GitLab note in main/sbbs on Monday, May 11, 2026 01:53:40
    https://gitlab.synchro.net/main/sbbs/-/merge_requests/538#note_8913

    I guess this aint happening then.

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Rob Swindell@VERT to GitLab note in main/sbbs on Monday, May 11, 2026 11:50:07
    https://gitlab.synchro.net/main/sbbs/-/merge_requests/538#note_8915

    The security concerns were never addressed, so no, so it won't be merged as it currently sits.

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net