4 Copyright (C) Derrell Lipman 2005
6 ** NOTE! The following LGPL license applies to the ldb
7 ** library. This does NOT imply that all of Samba is released
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * Component: ldb sqlite3 backend
30 * Description: core files for SQLITE3 backend
32 * Author: Derrell Lipman (based on Andrew Tridgell's LDAP backend)
37 #include "ldb/include/ldb.h"
38 #include "ldb/include/ldb_private.h"
39 #include "ldb/include/ldb_parse.h"
40 #include "ldb/include/ldb_explode_dn.h"
41 #include "ldb/ldb_sqlite3/ldb_sqlite3.h"
45 # define TRUE (! FALSE)
48 #define QUERY_NOROWS(lsqlite3, bRollbackOnError, sql...) \
50 if (lsqlite3_query_norows(lsqlite3, sql) != 0) { \
51 if (bRollbackOnError) { \
52 lsqlite3_query_norows(lsqlite3, \
59 #define QUERY_INT(lsqlite3, result_var, bRollbackOnError, sql...) \
61 if (lsqlite3_query_int(lsqlite3, &result_var, sql) != 0) { \
62 if (bRollbackOnError) { \
63 lsqlite3_query_norows(lsqlite3, \
71 * lsqlite3_query_norows()
73 * This function is used for queries that are not expected to return any rows,
74 * e.g. BEGIN, COMMIT, ROLLBACK, CREATE TABLE, INSERT, UPDATE, DELETE, etc.
75 * There are no provisions here for returning data from rows in a table, so do
76 * not pass SELECT queries to this function.
79 lsqlite3_query_norows(const struct lsqlite3_private *lsqlite3,
90 /* Begin access to variable argument list */
93 /* Format the query */
94 if ((p = sqlite3_vmprintf(pSql, args)) == NULL) {
99 * Prepare and execute the SQL statement. Loop allows retrying on
100 * certain errors, e.g. SQLITE_SCHEMA occurs if the schema changes,
101 * requiring retrying the operation.
103 for (bLoop = TRUE; bLoop; ) {
105 /* Compile the SQL statement into sqlite virtual machine */
106 if ((ret = sqlite3_prepare(lsqlite3->sqlite,
110 &pTail)) != SQLITE_OK) {
115 /* No rows expected, so just step through machine code once */
116 if ((ret = sqlite3_step(pStmt)) == SQLITE_SCHEMA) {
117 (void) sqlite3_finalize(pStmt);
119 } else if (ret != SQLITE_DONE) {
120 (void) sqlite3_finalize(pStmt);
125 /* Free the virtual machine */
126 if ((ret = sqlite3_finalize(pStmt)) == SQLITE_SCHEMA) {
127 (void) sqlite3_finalize(pStmt);
129 } else if (ret != SQLITE_OK) {
130 (void) sqlite3_finalize(pStmt);
136 * Normal condition is only one time through loop. Loop is
137 * rerun in error conditions, via "continue", above.
143 /* All done with variable argument list */
146 /* Free the memory we allocated for our query string */
154 * lsqlite3_query_int()
156 * This function is used for the common case of queries that return a single
159 * NOTE: If more than one value is returned by the query, all but the first
160 * one will be ignored.
163 lsqlite3_query_int(const struct lsqlite3_private * lsqlite3,
172 sqlite3_stmt * pStmt;
175 /* Begin access to variable argument list */
176 va_start(args, pSql);
178 /* Format the query */
179 if ((p = sqlite3_vmprintf(pSql, args)) == NULL) {
184 * Prepare and execute the SQL statement. Loop allows retrying on
185 * certain errors, e.g. SQLITE_SCHEMA occurs if the schema changes,
186 * requiring retrying the operation.
188 for (bLoop = TRUE; bLoop; ) {
190 /* Compile the SQL statement into sqlite virtual machine */
191 if ((ret = sqlite3_prepare(lsqlite3->sqlite,
195 &pTail)) != SQLITE_OK) {
200 /* No rows expected, so just step through machine code once */
201 if ((ret = sqlite3_step(pStmt)) == SQLITE_SCHEMA) {
202 (void) sqlite3_finalize(pStmt);
204 } else if (ret != SQLITE_ROW) {
205 (void) sqlite3_finalize(pStmt);
210 /* Get the value to be returned */
211 *pRet = sqlite3_column_int64(pStmt, 0);
213 /* Free the virtual machine */
214 if ((ret = sqlite3_finalize(pStmt)) == SQLITE_SCHEMA) {
215 (void) sqlite3_finalize(pStmt);
217 } else if (ret != SQLITE_OK) {
218 (void) sqlite3_finalize(pStmt);
224 * Normal condition is only one time through loop. Loop is
225 * rerun in error conditions, via "continue", above.
231 /* All done with variable argument list */
234 /* Free the memory we allocated for our query string */
243 * we don't need this right now, but will once we add some backend options
245 * find an option in an option list (a null terminated list of strings)
247 * this assumes the list is short. If it ever gets long then we really should
248 * do this in some smarter way
251 lsqlite3_option_find(const struct lsqlite3_private *lsqlite3,
255 size_t len = strlen(name);
257 if (!lsqlite3->options) return NULL;
259 for (i=0;lsqlite3->options[i];i++) {
260 if (strncmp(lsqlite3->options[i], name, len) == 0 &&
261 lsqlite3->options[i][len] == '=') {
262 return &lsqlite3->options[i][len+1];
271 callback function used in call to ldb_dn_fold() for determining whether an
272 attribute type requires case folding.
274 static int lsqlite3_case_fold_attr_required(void * hUserData,
277 // struct ldb_module * module = hUserData;
279 #warning "currently, all attributes require case folding"
288 lsqlite3_rename(struct ldb_module * module,
292 /* ignore ltdb specials */
293 if (olddn[0] == '@' ||newdn[0] == '@') {
297 #warning "lsqlite3_rename() is not yet supported"
305 lsqlite3_delete(struct ldb_module *module,
308 /* ignore ltdb specials */
316 #if 0 /* not currently used */
318 * free a search result
321 lsqlite3_search_free(struct ldb_module *module,
322 struct ldb_message **res)
331 * add a single set of ldap message values to a ldb_message
334 /* get things to compile before we actually implement this function */
340 #warning "lsqlite3_add_msg_attr() not yet implemented or used"
343 lsqlite3_add_msg_attr(struct ldb_context *ldb,
344 struct ldb_message *msg,
346 struct berval **bval)
350 struct ldb_message_element * el;
352 count = ldap_count_values_len(bval);
358 el = talloc_realloc(msg, msg->elements, struct ldb_message_element,
359 msg->num_elements + 1);
367 el = &msg->elements[msg->num_elements];
369 el->name = talloc_strdup(msg->elements, attr);
377 el->values = talloc_array(msg->elements, struct ldb_val, count);
383 for (i=0;i<count;i++) {
384 el->values[i].data = talloc_memdup(el->values, bval[i]->bv_val, bval[i]->bv_len);
385 if (!el->values[i].data) {
388 el->values[i].length = bval[i]->bv_len;
399 lsqlite3_parsetree_to_sql(struct ldb_module *module,
401 const struct ldb_parse_tree *t)
410 switch(t->operation) {
415 ret = lsqlite3_parsetree_to_sql(module,
417 t->u.list.elements[0]);
419 for (i = 1; i < t->u.list.num_elements; i++) {
421 lsqlite3_parsetree_to_sql(
424 t->u.list.elements[i]);
425 ret = talloc_asprintf_append(ret,
433 ret = talloc_asprintf("(\n"
442 lsqlite3_parsetree_to_sql(
445 t->u.list.elements[0]);
447 for (i = 1; i < t->u.list.num_elements; i++) {
449 lsqlite3_parsetree_to_sql(
452 t->u.list.elements[i]);
453 ret = talloc_asprintf_append(ret,
460 ret = talloc_asprintf("(\n"
469 lsqlite3_parsetree_to_sql(
473 ret = talloc_asprintf(hTalloc,
477 " WHERE eid NOT IN %s\n"
484 /* should never occur */
488 /* Get a case-folded copy of the attribute name */
489 pAttrName = ldb_casefold((struct ldb_context *) module,
493 * For simple searches, we want to retrieve the list of EIDs that
494 * match the criteria. We accomplish this by searching the
495 * appropriate table, ldb_attr_<attributeName>, for the eid
496 * corresponding to all matching values.
498 if (t->u.simple.value.length == 1 &&
499 (*(const char *) t->u.simple.value.data) == '*') {
501 * Special case for "attr_name=*". In this case, we want the
502 * eid corresponding to all values in the specified attribute
505 if ((p = sqlite3_mprintf("(\n"
507 " FROM ldb_attr_%q\n"
509 pAttrName)) == NULL) {
513 ret = talloc_strdup(hTalloc, p);
516 } else if (strcasecmp(t->u.simple.attr, "objectclass") == 0) {
518 * For object classes, we want to search for all objectclasses
519 * that are subclasses as well.
521 if ((p = sqlite3_mprintf(
524 " FROM ldb_attr_objectclass\n"
525 " WHERE attr_name IN\n"
526 " (SELECT class_name\n"
527 " FROM ldb_objectclasses\n"
528 " WHERE tree_key GLOB\n"
529 " (SELECT tree_key\n"
530 " FROM ldb_objectclasses\n"
531 " WHERE class_name = %Q) || '*')\n"
533 t->u.simple.value.data)) == NULL) {
537 ret = talloc_strdup(hTalloc, p);
541 /* A normal query. */
542 if ((p = sqlite3_mprintf("(\n"
544 " FROM ldb_attr_%q\n"
545 " WHERE attr_value = %Q\n"
548 t->u.simple.value.data)) == NULL) {
552 ret = talloc_strdup(hTalloc, p);
560 lsqlite3_parsetree_to_tablelist(struct ldb_module *module,
562 const struct ldb_parse_tree *t)
564 #warning "obtain talloc'ed array of attribute names for table list"
570 * search for matching records
573 lsqlite3_search(struct ldb_module * module,
574 const char * pBaseDN,
575 enum ldb_scope scope,
576 const char * pExpression,
577 const char * const attrs[],
578 struct ldb_message *** res)
582 char * sql_constraints;
585 struct ldb_parse_tree * pTree;
586 struct lsqlite3_private * lsqlite3 = module->private_data;
588 if (pBaseDN == NULL) {
592 /* Begin a transaction */
593 QUERY_NOROWS(lsqlite3, FALSE, "BEGIN IMMEDIATE;");
596 * Obtain the eid of the base DN
603 " WHERE attr_value = %Q;",
606 /* Parse the filter expression into a tree we can work with */
607 if ((pTree = ldb_parse_tree(module->ldb, pExpression)) == NULL) {
611 /* Allocate a temporary talloc context */
612 hTalloc = talloc_new(module->ldb);
614 /* Move the parse tree to our temporary context */
615 talloc_steal(hTalloc, pTree);
617 /* Convert filter into a series of SQL statements (constraints) */
618 sql_constraints = lsqlite3_parsetree_to_sql(module, hTalloc, pTree);
620 /* Get the list of attribute names to use as our extra table list */
621 table_list = lsqlite3_parsetree_to_tablelist(module, hTalloc, pTree);
624 case LDB_SCOPE_DEFAULT:
625 case LDB_SCOPE_SUBTREE:
626 sql = sqlite3_mprintf(
627 "SELECT entry.entry_data\n"
628 " FROM ldb_entry AS entry\n"
629 " WHERE entry.eid IN\n"
630 " (SELECT DISTINCT ldb_entry.eid\n"
632 " ldb_descendants,\n"
634 " WHERE ldb_descendants.aeid = %lld\n"
635 " AND ldb_entry.eid = ldb_descendants.deid\n"
636 " AND ldap_entry.eid IN\n"
645 sql = sqlite3_mprintf(
646 "SELECT entry.entry_data\n"
647 " FROM ldb_entry AS entry\n"
648 " WHERE entry.eid IN\n"
649 " (SELECT DISTINCT ldb_entry.eid\n"
651 " WHERE ldb_entry.eid = %lld\n"
652 " AND ldb_entry.eid IN\n"
660 case LDB_SCOPE_ONELEVEL:
661 sql = sqlite3_mprintf(
662 "SELECT entry.entry_data\n"
663 " FROM ldb_entry AS entry\n"
664 " WHERE entry.eid IN\n"
665 " (SELECT DISTINCT ldb_entry.eid\n"
666 " FROM ldb_entry AS pchild, "
668 " WHERE ldb_entry.eid = pchild.eid "
669 " AND pchild.peid = %lld "
670 " AND ldb_entry.eid IN\n"
679 #warning "retrieve and return the result set of the search here"
681 /* End the transaction */
682 QUERY_NOROWS(lsqlite3, FALSE, "END TRANSACTION;");
689 lsqlite3_new_attr(struct ldb_module * module,
692 struct lsqlite3_private * lsqlite3 = module->private_data;
694 /* NOTE: pAttrName is assumed to already be case-folded here! */
695 QUERY_NOROWS(lsqlite3,
697 "CREATE TABLE ldb_attr_%q "
699 " eid INTEGER REFERENCES ldb_entry, "
708 * Issue a series of SQL statements to implement the ADD/MODIFY/DELETE
709 * requests in the ldb_message
712 lsqlite3_msg_to_sql(struct ldb_module * module,
713 const struct ldb_message * msg,
721 struct lsqlite3_private * lsqlite3 = module->private_data;
723 for (i = 0; i < msg->num_elements; i++) {
724 const struct ldb_message_element *el = &msg->elements[i];
727 flags = LDB_FLAG_MOD_ADD;
729 flags = el->flags & LDB_FLAG_MOD_MASK;
732 /* Get a case-folded copy of the attribute name */
733 pAttrName = ldb_casefold((struct ldb_context *) module,
736 if (flags == LDB_FLAG_MOD_ADD) {
737 /* Create the attribute table if it doesn't exist */
738 if (lsqlite3_new_attr(module, pAttrName) != 0) {
743 /* For each value of the specified attribute name... */
744 for (j = 0; j < el->num_values; j++) {
746 /* ... bind the attribute value, if necessary */
748 case LDB_FLAG_MOD_ADD:
749 QUERY_NOROWS(lsqlite3,
751 "INSERT INTO ldb_attr_%q "
752 " (eid, attr_value) "
756 eid, el->values[j].data);
757 QUERY_NOROWS(lsqlite3,
761 " add_attr(entry_data, "
763 " WHERE eid = %lld;",
764 el->name, el->values[j].data,
769 case LDB_FLAG_MOD_REPLACE:
770 QUERY_NOROWS(lsqlite3,
772 "UPDATE ldb_attr_%q "
773 " SET attr_value = %Q "
774 " WHERE eid = %lld;",
778 QUERY_NOROWS(lsqlite3,
782 " mod_attr(entry_data, "
784 " WHERE eid = %lld;",
785 el->name, el->values[j].data,
789 case LDB_FLAG_MOD_DELETE:
790 /* No additional parameters to this query */
791 QUERY_NOROWS(lsqlite3,
793 "DELETE FROM ldb_attr_%q "
795 " AND attr_value = %Q;",
799 QUERY_NOROWS(lsqlite3,
803 " del_attr(entry_data, "
805 " WHERE eid = %lld;",
806 el->name, el->values[j].data,
818 lsqlite3_new_dn(struct ldb_module * module,
822 struct ldb_dn * pExplodedDN;
823 struct ldb_context * ldb = module->ldb;
824 // struct lsqlite3_private * lsqlite3 = module->private_data;
826 /* Explode and normalize the DN */
831 lsqlite3_case_fold_attr_required)) == NULL) {
835 #warning "*** lsqlite3_new_dn() not yet fully implemented ***"
844 lsqlite3_add(struct ldb_module *module,
845 const struct ldb_message *msg)
848 struct lsqlite3_private * lsqlite3 = module->private_data;
850 /* ignore ltdb specials */
851 if (msg->dn[0] == '@') {
855 /* Begin a transaction */
856 QUERY_NOROWS(lsqlite3, FALSE, "BEGIN EXCLUSIVE;");
859 * Build any portions of the directory tree that don't exist. If the
860 * final component already exists, it's an error.
862 if (lsqlite3_new_dn(module, msg->dn, &eid) != 0) {
863 QUERY_NOROWS(lsqlite3, FALSE, "ROLLBACK;");
867 /* Add attributes to this new entry */
868 if (lsqlite3_msg_to_sql(module, msg, eid, FALSE) != 0) {
869 QUERY_NOROWS(lsqlite3, FALSE, "ROLLBACK;");
873 /* Everything worked. Commit it! */
874 QUERY_NOROWS(lsqlite3, TRUE, "COMMIT;");
883 lsqlite3_modify(struct ldb_module *module,
884 const struct ldb_message *msg)
886 struct lsqlite3_private * lsqlite3 = module->private_data;
888 /* ignore ltdb specials */
889 if (msg->dn[0] == '@') {
893 /* Begin a transaction */
894 QUERY_NOROWS(lsqlite3, FALSE, "BEGIN EXCLUSIVE;");
896 /* Everything worked. Commit it! */
897 QUERY_NOROWS(lsqlite3, TRUE, "COMMIT;");
902 lsqlite3_lock(struct ldb_module *module,
903 const char *lockname)
905 if (lockname == NULL) {
909 /* TODO implement a local locking mechanism here */
915 lsqlite3_unlock(struct ldb_module *module,
916 const char *lockname)
918 if (lockname == NULL) {
922 /* TODO implement a local locking mechanism here */
928 * return extended error information
931 lsqlite3_errstring(struct ldb_module *module)
933 struct lsqlite3_private * lsqlite3 = module->private_data;
935 return sqlite3_errmsg(lsqlite3->sqlite);
939 static const struct ldb_module_ops lsqlite3_ops = {
953 lsqlite3_destructor(void *p)
955 struct lsqlite3_private * lsqlite3 = p;
957 (void) sqlite3_close(lsqlite3->sqlite);
962 lsqlite3_initialize(struct lsqlite3_private *lsqlite3,
970 const char * schema =
971 "-- ------------------------------------------------------"
973 "PRAGMA auto_vacuum=1;"
975 "-- ------------------------------------------------------"
979 "-- ------------------------------------------------------"
981 "CREATE TABLE ldb_info AS"
982 " SELECT 'LDB' AS database_type,"
985 "-- ------------------------------------------------------"
989 " * The entry table holds the information about an entry. "
990 " * This table is used to obtain the EID of the entry and to "
991 " * support scope=one and scope=base. The parent and child"
992 " * table is included in the entry table since all the other"
993 " * attributes are dependent on EID."
995 "CREATE TABLE ldb_entry"
997 " -- Unique identifier of this LDB entry"
998 " eid INTEGER PRIMARY KEY,"
1000 " -- Unique identifier of the parent LDB entry"
1001 " peid INTEGER REFERENCES ldb_entry,"
1003 " -- Distinguished name of this entry"
1006 " -- Time when the entry was created"
1007 " create_timestamp INTEGER,"
1009 " -- Time when the entry was last modified"
1010 " modify_timestamp INTEGER,"
1012 " -- Attributes of this entry, in the form"
1013 " -- attr\1value\0[attr\1value\0]*\0"
1019 " * The purpose of the descendant table is to support the"
1020 " * subtree search feature. For each LDB entry with a unique"
1021 " * ID (AEID), this table contains the unique identifiers"
1022 " * (DEID) of the descendant entries."
1024 " * For evern entry in the directory, a row exists in this"
1025 " * table for each of its ancestors including itself. The "
1026 " * size of the table depends on the depth of each entry. In "
1027 " * the worst case, if all the entries were at the same "
1028 " * depth, the number of rows in the table is O(nm) where "
1029 " * n is the number of nodes in the directory and m is the "
1030 " * depth of the tree. "
1032 "CREATE TABLE ldb_descendants"
1034 " -- The unique identifier of the ancestor LDB entry"
1035 " aeid INTEGER REFERENCES ldb_entry,"
1037 " -- The unique identifier of the descendant LDB entry"
1038 " deid INTEGER REFERENCES ldb_entry"
1042 "CREATE TABLE ldb_object_classes"
1044 " -- Object classes are inserted into this table to track"
1045 " -- their class hierarchy. 'top' is the top-level class"
1046 " -- of which all other classes are subclasses."
1047 " class_name TEXT PRIMARY KEY,"
1049 " -- tree_key tracks the position of the class in"
1051 " tree_key TEXT UNIQUE"
1055 " * There is one attribute table per searchable attribute."
1058 "CREATE TABLE ldb_attr_ATTRIBUTE_NAME"
1060 " -- The unique identifier of the LDB entry"
1061 " eid INTEGER REFERENCES ldb_entry,"
1063 " -- Normalized attribute value"
1069 "-- ------------------------------------------------------"
1073 "-- ------------------------------------------------------"
1076 "CREATE TRIGGER ldb_entry_insert_tr"
1082 " SET create_timestamp = strftime('%s', 'now'),"
1083 " modify_timestamp = strftime('%s', 'now')"
1084 " WHERE eid = new.eid;"
1087 "CREATE TRIGGER ldb_entry_update_tr"
1093 " SET modify_timestamp = strftime('%s', 'now')"
1094 " WHERE eid = old.eid;"
1097 "-- ------------------------------------------------------"
1098 "-- Table initialization"
1100 "/* We need an implicit 'top' level object class */"
1101 "INSERT INTO ldb_attributes (attr_name,"
1103 " SELECT 'top', '';"
1105 "-- ------------------------------------------------------"
1109 "-- ------------------------------------------------------"
1112 /* Skip protocol indicator of url */
1113 if (strncmp(url, "sqlite://", 9) != 0) {
1114 return SQLITE_MISUSE;
1120 * See if we'll be creating a new database, or opening an existing one
1122 /* Try to open the (possibly empty/non-existent) database */
1123 if ((ret = sqlite3_open(p, &lsqlite3->sqlite)) != SQLITE_OK) {
1127 /* Begin a transaction */
1128 QUERY_NOROWS(lsqlite3, FALSE, "BEGIN EXCLUSIVE;");
1130 /* Determine if this is a new database */
1135 " FROM sqlite_master "
1136 " WHERE type = 'table';");
1138 if (queryInt == 0) {
1140 * Create the database schema
1142 for (pTail = discard_const_p(char, schema); pTail != NULL; ) {
1144 if ((ret = sqlite3_prepare(
1149 &pTail)) != SQLITE_OK ||
1150 (ret = sqlite3_step(stmt)) != SQLITE_DONE ||
1151 (ret = sqlite3_finalize(stmt)) != SQLITE_OK) {
1153 (void) sqlite3_close(lsqlite3->sqlite);
1159 * Ensure that the database we opened is one of ours
1161 if (lsqlite3_query_int(lsqlite3,
1164 " (SELECT COUNT(*) = 3"
1165 " FROM sqlite_master "
1166 " WHERE type = 'table' "
1170 " 'ldb_descendants', "
1171 " 'ldb_object_classes' "
1177 " WHERE database_type = 'LDB' "
1178 " AND version = '1.0'"
1182 /* It's not one that we created. See ya! */
1183 (void) sqlite3_close(lsqlite3->sqlite);
1184 return SQLITE_MISUSE;
1192 * connect to the database
1194 struct ldb_context *
1195 lsqlite3_connect(const char *url,
1197 const char *options[])
1201 struct ldb_context * ldb = NULL;
1202 struct lsqlite3_private * lsqlite3 = NULL;
1204 ldb = talloc(NULL, struct ldb_context);
1210 lsqlite3 = talloc(ldb, struct lsqlite3_private);
1216 lsqlite3->sqlite = NULL;
1217 lsqlite3->options = NULL;
1218 lsqlite3->lock_count = 0;
1220 ret = lsqlite3_initialize(lsqlite3, url);
1221 if (ret != SQLITE_OK) {
1225 talloc_set_destructor(lsqlite3, lsqlite3_destructor);
1227 ldb->modules = talloc(ldb, struct ldb_module);
1228 if (!ldb->modules) {
1232 ldb->modules->ldb = ldb;
1233 ldb->modules->prev = ldb->modules->next = NULL;
1234 ldb->modules->private_data = lsqlite3;
1235 ldb->modules->ops = &lsqlite3_ops;
1239 * take a copy of the options array, so we don't have to rely
1240 * on the caller keeping it around (it might be dynamic)
1242 for (i=0;options[i];i++) ;
1244 lsqlite3->options = talloc_array(lsqlite3, char *, i+1);
1245 if (!lsqlite3->options) {
1249 for (i=0;options[i];i++) {
1251 lsqlite3->options[i+1] = NULL;
1252 lsqlite3->options[i] =
1253 talloc_strdup(lsqlite3->options, options[i]);
1254 if (!lsqlite3->options[i]) {
1263 if (lsqlite3->sqlite != NULL) {
1264 (void) sqlite3_close(lsqlite3->sqlite);