LuaSQLite3

Check-in [f3fe11aaa4]
Login

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

Overview
Comment:Add load_extension. Fix PUSH_INT64 for Lua < 5.3.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f3fe11aaa44aa262539805a7b38c47f5b06a8536
User & Date: e 2015-01-05 21:24:03
References
2015-01-05
21:44 Closed ticket [2d23a7bdcf]: Patch to add a "db:load_extension" function plus 5 other changes artifact: f659e10c78 user: e
Context
2015-01-05
21:26
Update rockspec for bug fix release. check-in: 1d5512efeb user: e tags: fsl_9v, trunk
21:24
Add load_extension. Fix PUSH_INT64 for Lua < 5.3. check-in: f3fe11aaa4 user: e tags: trunk
20:16
Update wiki doc check-in: 7c2c1f829c user: e tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lsqlite3.c.

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
....
1199
1200
1201
1202
1203
1204
1205




























1206
1207
1208
1209
1210
1211
1212
....
2014
2015
2016
2017
2018
2019
2020

2021
2022
2023
2024
2025
2026
2027
        else { \
            lua_Number n = (lua_Number)i64; \
            if (n == i64) lua_pushnumber(L, n); \
            else fallback; \
        } \
    } while (0)
#else
#define PUSH_INT64(L,i64in,str,sz) \
    do { \
        sqlite_int64 i64 = i64in; \
        lua_Number n = (lua_Number)i64; \
        if (n == i64) lua_pushnumber(L, n); \
        else fallback; \
    } while (0)
#endif
................................................................................
    }
    sqlite3_create_collation_v2(db->db, collname, SQLITE_UTF8,
        (void *)co,
        (int(*)(void*,int,const void*,int,const void*))collfunc,
        (void(*)(void*))collfree);
    return 0;
}





























/*
** trace callback:
** Params: database, callback function, userdata
**
** callback function:
** Params: userdata, sql
................................................................................
    {"errmsg",              db_errmsg               },
    {"error_message",       db_errmsg               },
    {"interrupt",           db_interrupt            },

    {"create_function",     db_create_function      },
    {"create_aggregate",    db_create_aggregate     },
    {"create_collation",    db_create_collation     },


    {"trace",               db_trace                },
    {"progress_handler",    db_progress_handler     },
    {"busy_timeout",        db_busy_timeout         },
    {"busy_handler",        db_busy_handler         },
#if !defined(LSQLITE_OMIT_UPDATE_HOOK) || !LSQLITE_OMIT_UPDATE_HOOK
    {"update_hook",         db_update_hook          },







|







 







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







 







>







135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
....
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
....
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
        else { \
            lua_Number n = (lua_Number)i64; \
            if (n == i64) lua_pushnumber(L, n); \
            else fallback; \
        } \
    } while (0)
#else
#define PUSH_INT64(L,i64in,fallback) \
    do { \
        sqlite_int64 i64 = i64in; \
        lua_Number n = (lua_Number)i64; \
        if (n == i64) lua_pushnumber(L, n); \
        else fallback; \
    } while (0)
#endif
................................................................................
    }
    sqlite3_create_collation_v2(db->db, collname, SQLITE_UTF8,
        (void *)co,
        (int(*)(void*,int,const void*,int,const void*))collfunc,
        (void(*)(void*))collfree);
    return 0;
}

/* Thanks to Wolfgang Oertl...
*/
static int db_load_extension(lua_State *L) {
    sdb *db=lsqlite_checkdb(L,1);
    const char *extname=luaL_optstring(L,2,NULL);
    const char *entrypoint=luaL_optstring(L,3,NULL);
    int result;
    char *errmsg = NULL;

    if (extname == NULL) {
        result = sqlite3_enable_load_extension(db->db,0); /* disable extension loading */
    }
    else {
        sqlite3_enable_load_extension(db->db,1); /* enable extension loading */
        result = sqlite3_load_extension(db->db,extname,entrypoint,&errmsg);
    }

    if (result == SQLITE_OK) {
        lua_pushboolean(L,1);
        return 1;
    }

    lua_pushboolean(L,0); /* so, assert(load_extension(...)) works */
    lua_pushstring(L,errmsg);
    sqlite3_free(errmsg);
    return 2;
}

/*
** trace callback:
** Params: database, callback function, userdata
**
** callback function:
** Params: userdata, sql
................................................................................
    {"errmsg",              db_errmsg               },
    {"error_message",       db_errmsg               },
    {"interrupt",           db_interrupt            },

    {"create_function",     db_create_function      },
    {"create_aggregate",    db_create_aggregate     },
    {"create_collation",    db_create_collation     },
    {"load_extension",      db_load_extension       },

    {"trace",               db_trace                },
    {"progress_handler",    db_progress_handler     },
    {"busy_timeout",        db_busy_timeout         },
    {"busy_handler",        db_busy_handler         },
#if !defined(LSQLITE_OMIT_UPDATE_HOOK) || !LSQLITE_OMIT_UPDATE_HOOK
    {"update_hook",         db_update_hook          },