LuaSQLite3

Check-in [a691fc984b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add stmt:last_insert_rowid() per request; fix tag in rockspec
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a691fc984b3aa641f4999bcdb055e4e8d9079e4c
User & Date: e 2015-01-04 22:44:04
Context
2015-01-05
02:28
Update HISTORY for 0.9.2 check-in: 8a088f1459 user: e tags: fsl_9u, trunk
2015-01-04
22:44
Add stmt:last_insert_rowid() per request; fix tag in rockspec check-in: a691fc984b user: e tags: trunk
22:13
Updated for Lua 5.3. Use sqlite3_prepare_v2. check-in: d59e31d19c user: e tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lsqlite3-0.9.2-1.rockspec.

1
2
3
4
5
6
7
8
9
10
11
12
package = "lsqlite3"
version = "0.9.2-1"
source = {
    url = "http://lua.sqlite.org/index.cgi/zip/lsqlite3_fsl09t.zip?uuid=fsl_9t",
    file = "lsqlite3_fsl09t.zip"
}
description = {
    summary = "A binding for Lua to the SQLite3 database library",
    detailed = [[
        lsqlite3 is a thin wrapper around the public domain SQLite3 database engine. 
        The lsqlite3 module supports the creation and manipulation of SQLite3 databases. 
        After a require('lsqlite3') the exported functions are called with prefix sqlite3. 



|
|







1
2
3
4
5
6
7
8
9
10
11
12
package = "lsqlite3"
version = "0.9.2-1"
source = {
    url = "http://lua.sqlite.org/index.cgi/zip/lsqlite3_fsl09u.zip?uuid=fsl_9u",
    file = "lsqlite3_fsl09u.zip"
}
description = {
    summary = "A binding for Lua to the SQLite3 database library",
    detailed = [[
        lsqlite3 is a thin wrapper around the public domain SQLite3 database engine. 
        The lsqlite3 module supports the creation and manipulation of SQLite3 databases. 
        After a require('lsqlite3') the exported functions are called with prefix sqlite3. 

Changes to lsqlite3.c.

268
269
270
271
272
273
274
275
276
277
278

279
280
281
282
283
284
285
...
353
354
355
356
357
358
359








360
361
362
363
364
365
366
....
2125
2126
2127
2128
2129
2130
2131


2132
2133
2134
2135
2136
2137
2138
            lua_pop(L,2);
        } else {
          break;
        }
    }
#else
    result = sqlite3_step(svm->vm);

    if ( result==SQLITE_ERROR ) {
        sqlite3_reset (svm->vm);
    }

#endif
    return result;
}

static sdb_vm *lsqlite_getvm(lua_State *L, int index) {
    sdb_vm *svm = (sdb_vm*)luaL_checkudata(L, index, sqlite_vm_meta);
    if (svm == NULL) luaL_argerror(L, index, "bad sqlite virtual machine");
................................................................................
}

static void dbvm_check_bind_index(lua_State *L, sdb_vm *svm, int index) {
    if (index < 1 || index > sqlite3_bind_parameter_count(svm->vm)) {
        luaL_error(L, "bind index out of range [1..%d]", sqlite3_bind_parameter_count(svm->vm));
    }
}









/*
** =======================================================
** Virtual Machine - generic info
** =======================================================
*/
static int dbvm_columns(lua_State *L) {
................................................................................

    {"get_named_values",    dbvm_get_named_values   },
    {"get_named_types",     dbvm_get_named_types    },

    {"rows",                dbvm_rows               },
    {"urows",               dbvm_urows              },
    {"nrows",               dbvm_nrows              },



    /* compatibility names (added by request) */
    {"idata",               dbvm_get_values         },
    {"inames",              dbvm_get_names          },
    {"itypes",              dbvm_get_types          },
    {"data",                dbvm_get_named_values   },
    {"type",                dbvm_get_named_types    },







<
|
|
<
>







 







>
>
>
>
>
>
>
>







 







>
>







268
269
270
271
272
273
274

275
276

277
278
279
280
281
282
283
284
...
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
....
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
            lua_pop(L,2);
        } else {
          break;
        }
    }
#else
    result = sqlite3_step(svm->vm);

//    if ( result==SQLITE_ERROR ) {
//        sqlite3_reset (svm->vm);

//    }
#endif
    return result;
}

static sdb_vm *lsqlite_getvm(lua_State *L, int index) {
    sdb_vm *svm = (sdb_vm*)luaL_checkudata(L, index, sqlite_vm_meta);
    if (svm == NULL) luaL_argerror(L, index, "bad sqlite virtual machine");
................................................................................
}

static void dbvm_check_bind_index(lua_State *L, sdb_vm *svm, int index) {
    if (index < 1 || index > sqlite3_bind_parameter_count(svm->vm)) {
        luaL_error(L, "bind index out of range [1..%d]", sqlite3_bind_parameter_count(svm->vm));
    }
}

static int dbvm_last_insert_rowid(lua_State *L) {
    sdb_vm *svm = lsqlite_checkvm(L, 1);
    /* conversion warning: int64 -> luaNumber */
    sqlite_int64 rowid = sqlite3_last_insert_rowid(svm->db->db);
    PUSH_INT64(L, rowid, lua_pushfstring(L, "%ll", rowid));
    return 1;
}

/*
** =======================================================
** Virtual Machine - generic info
** =======================================================
*/
static int dbvm_columns(lua_State *L) {
................................................................................

    {"get_named_values",    dbvm_get_named_values   },
    {"get_named_types",     dbvm_get_named_types    },

    {"rows",                dbvm_rows               },
    {"urows",               dbvm_urows              },
    {"nrows",               dbvm_nrows              },

    {"last_insert_rowid",   dbvm_last_insert_rowid  },

    /* compatibility names (added by request) */
    {"idata",               dbvm_get_values         },
    {"inames",              dbvm_get_names          },
    {"itypes",              dbvm_get_types          },
    {"data",                dbvm_get_named_values   },
    {"type",                dbvm_get_named_types    },

Changes to test/tests-sqlite3.lua.

435
436
437
438
439
440
441





















442
443
444
445
446
447
448
  args.name = "Hello boys"
  assert( stmt:bind_names(args) )
  assert_number( stmt:step() )
  assert_number( stmt:reset() )
  st.check_content{ "Hello World", "Hello Lua", "Hello sqlite3",  "Hello boys", "Hello girls" }
  assert_number( stmt:finalize() )
end
























--------------------------------
-- Tests binding of arguments --
--------------------------------








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
  args.name = "Hello boys"
  assert( stmt:bind_names(args) )
  assert_number( stmt:step() )
  assert_number( stmt:reset() )
  st.check_content{ "Hello World", "Hello Lua", "Hello sqlite3",  "Hello boys", "Hello girls" }
  assert_number( stmt:finalize() )
end

function st.test_last_insert_rowid()
  local stmt = assert_userdata( st.db:prepare("INSERT INTO test VALUES (:id, :name)")  )
  local args = { }
  args.id = 5
  args.name = "Hello girls"
  assert( stmt:bind_names(args) )
  assert_number( stmt:step() )
  assert_number( stmt:reset() )
  assert_number( stmt:last_insert_rowid() )
  assert_equal( stmt:last_insert_rowid(), 4 )
  args.id = 4
  args.name = "Hello boys"
  assert( stmt:bind_names(args) )
  assert_number( stmt:step() )
  assert_number( stmt:reset() )
  assert_number( stmt:last_insert_rowid() )
  assert_equal( stmt:last_insert_rowid(), 5 )
  st.check_content{ "Hello World", "Hello Lua", "Hello sqlite3",  "Hello boys", "Hello girls" }
  assert_number( stmt:finalize() )
end



--------------------------------
-- Tests binding of arguments --
--------------------------------