dbd/sqlite3/connection.c

changeset 22
fd78e9cdc6e9
parent 14
98192b7d4e89
child 32
03ed0ca09837
equal deleted inserted replaced
21:7956401a0c5e 22:fd78e9cdc6e9
143 } 143 }
144 144
145 lua_pushnil(L); 145 lua_pushnil(L);
146 lua_pushstring(L, DBI_ERR_DB_UNAVAILABLE); 146 lua_pushstring(L, DBI_ERR_DB_UNAVAILABLE);
147 return 2; 147 return 2;
148 }
149
150 /*
151 * quoted = connection:quote(str)
152 */
153 static int connection_quote(lua_State *L) {
154 connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_SQLITE_CONNECTION);
155 size_t len;
156 const char *from = luaL_checklstring(L, 2, &len);
157 char *to;
158
159 if (!conn->sqlite) {
160 luaL_error(L, DBI_ERR_DB_UNAVAILABLE);
161 }
162
163 to = sqlite3_mprintf("%q", from);
164
165 lua_pushstring(L, to);
166 sqlite3_free(to);
167
168 return 1;
148 } 169 }
149 170
150 /* 171 /*
151 * success = connection:rollback() 172 * success = connection:rollback()
152 */ 173 */
185 {"autocommit", connection_autocommit}, 206 {"autocommit", connection_autocommit},
186 {"close", connection_close}, 207 {"close", connection_close},
187 {"commit", connection_commit}, 208 {"commit", connection_commit},
188 {"ping", connection_ping}, 209 {"ping", connection_ping},
189 {"prepare", connection_prepare}, 210 {"prepare", connection_prepare},
211 {"quote", connection_quote},
190 {"rollback", connection_rollback}, 212 {"rollback", connection_rollback},
191 {NULL, NULL} 213 {NULL, NULL}
192 }; 214 };
193 215
194 /* 216 /*

mercurial