lua_dbd.c revision 155bbc7af7b1ce46533c6e273a5921ca75813ad2
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele * Licensed to the Apache Software Foundation (ASF) under one or more
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele * contributor license agreements. See the NOTICE file distributed with
5f5d1b4cc970b7f06ff8ef6526128e9a27303d88nd * this work for additional information regarding copyright ownership.
acc36ab93565d2880447d535da6ca6e5feac7a70nd * The ASF licenses this file to You under the Apache License, Version 2.0
acc36ab93565d2880447d535da6ca6e5feac7a70nd * (the "License"); you may not use this file except in compliance with
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding * the License. You may obtain a copy of the License at
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding * Unless required by applicable law or agreed to in writing, software
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding * distributed under the License is distributed on an "AS IS" BASIS,
acc36ab93565d2880447d535da6ca6e5feac7a70nd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
acc36ab93565d2880447d535da6ca6e5feac7a70nd * See the License for the specific language governing permissions and
acc36ab93565d2880447d535da6ca6e5feac7a70nd * limitations under the License.
7db9f691a00ead175b03335457ca296a33ddf31bndstatic APR_OPTIONAL_FN_TYPE(ap_dbd_close) *lua_ap_dbd_close = NULL;
252b32956857ad89fc9ee708c4c6eb36097a647cerikabelestatic APR_OPTIONAL_FN_TYPE(ap_dbd_open) *lua_ap_dbd_open = NULL;
e50df6c711553f98103f1e0802f7de8c59be7cddslivestatic request_rec *ap_lua_check_request_rec(lua_State *L, int index)
252b32956857ad89fc9ee708c4c6eb36097a647cerikabelestatic lua_db_handle *lua_get_db_handle(lua_State *L)
252b32956857ad89fc9ee708c4c6eb36097a647cerikabelestatic lua_db_result_set *lua_get_result_set(lua_State *L)
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele return (lua_db_result_set *) lua_topointer(L, -1);
3f2fa24c621652779fd6706116a35b49c6dc26cand =============================================================================
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele db:close(): Closes an open database connection.
e50df6c711553f98103f1e0802f7de8c59be7cddslive =============================================================================
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele /*~~~~~~~~~~~~~~~~~~~~*/
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele /*~~~~~~~~~~~~~~~~~~~~*/
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele lua_ap_dbd_close = APR_RETRIEVE_OPTIONAL_FN(ap_dbd_close);
91dbfe27f56a07b53ec19068fdb47581476d5c3brbowen if (db->dbdhandle) lua_ap_dbd_close(db->server, db->dbdhandle);
91dbfe27f56a07b53ec19068fdb47581476d5c3brbowen =============================================================================
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele db:__gc(): Garbage collecting function.
e50df6c711553f98103f1e0802f7de8c59be7cddslive =============================================================================
19e48954d3cfb4f573a99866b0071b6aaa62723ckess /*~~~~~~~~~~~~~~~~*/
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele /*~~~~~~~~~~~~~~~~~~~~*/
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele lua_ap_dbd_close = APR_RETRIEVE_OPTIONAL_FN(ap_dbd_close);
19e48954d3cfb4f573a99866b0071b6aaa62723ckess if (db->dbdhandle) lua_ap_dbd_close(db->server, db->dbdhandle);
19e48954d3cfb4f573a99866b0071b6aaa62723ckess =============================================================================
19e48954d3cfb4f573a99866b0071b6aaa62723ckess db:active(): Returns true if the connection to the db is still active.
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele =============================================================================
91dbfe27f56a07b53ec19068fdb47581476d5c3brbowen /*~~~~~~~~~~~~~~~~~~~~*/
e50df6c711553f98103f1e0802f7de8c59be7cddslive /*~~~~~~~~~~~~~~~~~~~~*/
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele rc = apr_dbd_check_conn(db->driver, db->pool, db->handle);
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele =============================================================================
91dbfe27f56a07b53ec19068fdb47581476d5c3brbowen db:query(statement): Executes the given database query and returns the
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele number of rows affected. If an error is encountered, returns nil as the
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele first parameter and the error message as the second.
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele =============================================================================
e50df6c711553f98103f1e0802f7de8c59be7cddslive /*~~~~~~~~~~~~~~~~~~~~~~~*/
a6fc6b44b7f8ad7390864b3555341d3abf867f7end int x = 0;
e50df6c711553f98103f1e0802f7de8c59be7cddslive const char *statement;
91dbfe27f56a07b53ec19068fdb47581476d5c3brbowen /*~~~~~~~~~~~~~~~~~~~~~~~*/
e50df6c711553f98103f1e0802f7de8c59be7cddslive rc = apr_dbd_query(db->driver, db->handle, &x, statement);
e50df6c711553f98103f1e0802f7de8c59be7cddslive /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele const char *err = apr_dbd_error(db->driver, db->handle, rc);
91dbfe27f56a07b53ec19068fdb47581476d5c3brbowen /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
e50df6c711553f98103f1e0802f7de8c59be7cddslive =============================================================================
e50df6c711553f98103f1e0802f7de8c59be7cddslive db:escape(string): Escapes a string for safe use in the given database type.
e50df6c711553f98103f1e0802f7de8c59be7cddslive =============================================================================
19e48954d3cfb4f573a99866b0071b6aaa62723ckess /*~~~~~~~~~~~~~~~~~~~~~*/
19e48954d3cfb4f573a99866b0071b6aaa62723ckess const char *statement;
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele const char *escaped = 0;
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele /*~~~~~~~~~~~~~~~~~~~~~*/
e50df6c711553f98103f1e0802f7de8c59be7cddslive escaped = apr_dbd_escape(db->driver, r->pool, statement,
a6fc6b44b7f8ad7390864b3555341d3abf867f7end =============================================================================
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele resultset(N): Fetches one or more rows from a result set.
252b32956857ad89fc9ee708c4c6eb36097a647cerikabele =============================================================================
lua_settop(L,0);
if (row_no == 0) {
lua_newtable(L);
lua_newtable(L);
if (entry) {
row_no++;
lua_newtable(L);
if (entry) {
const char *statement;
request_rec *r;
int cols;
if (cols > 0) {
lua_newtable(L);
lua_pushnil(L);
if (err) {
lua_pushboolean(L, 0);
const char **vars;
int x, have;
lua_pushboolean(L, 0);
for (x = 0; x < have; x++) {
int cols;
lua_newtable(L);
lua_pushnil(L);
if (err) {
lua_pushboolean(L, 0);
const char **vars;
int x, have;
lua_pushboolean(L, 0);
for (x = 0; x < have; x++) {
int affected = 0;
lua_pushnil(L);
if (err) {
lua_pushboolean(L, 0);
request_rec *r;
int need = 0;
at++;
need++;
lua_pushnil(L);
if (err) {
lua_newtable(L);
const char *tag;
request_rec *r;
lua_pushnil(L);
lua_newtable(L);
lua_newtable(L);
return db;
const char *type;
const char *arguments;
const char *error = 0;
request_rec *r;
lua_settop(L, 0);
if (lua_ap_dbd_open)
if (dbdhandle) {
lua_pushnil(L);
"Could not acquire connection from mod_dbd. If your database is running, this may indicate a permission problem.");
lua_pushnil(L);
lua_settop(L, 0);
lua_pushnil(L);
if (error) {
lua_pushnil(L);
lua_pushnil(L);
type);
lua_pushnil(L);