4 Copyright (C) Andrew Tridgell 2004
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)
36 #include "ldb/include/ldb.h"
37 #include "ldb/include/ldb_private.h"
38 #include "ldb/ldb_sqlite3/ldb_sqlite3.h"
40 #undef SQL_EXEC /* just in case; not expected to be defined */
41 #define SQL_EXEC(lsqlite3, query, reset) \
44 sqlite3_step(lsqlite3->queries.query); \
45 if (lsqlite3->last_rc == SQLITE_BUSY || reset) \
46 (void) sqlite3_reset(lsqlite3->queries.query); \
47 } while lsqlite3->last_rc == SQLITE_BUSY;
53 * we don't need this right now, but will once we add some backend options
55 * find an option in an option list (a null terminated list of strings)
57 * this assumes the list is short. If it ever gets long then we really should
58 * do this in some smarter way
61 lsqlite3_option_find(const struct lsqlite3_private *lsqlite3,
65 size_t len = strlen(name);
67 if (!lsqlite3->options) return NULL;
69 for (i=0;lsqlite3->options[i];i++) {
70 if (strncmp(lsqlite3->options[i], name, len) == 0 &&
71 lsqlite3->options[i][len] == '=') {
72 return &lsqlite3->options[i][len+1];
84 lsqlite3_rename(struct ldb_module *module,
89 struct lsqlite3_private * lsqlite3 = module->private_data;
91 /* ignore ltdb specials */
92 if (olddn[0] == '@' ||newdn[0] == '@') {
96 /* Bind old distinguished names */
97 column = sqlite3_bind_parameter_index(lsqlite3->queries.renameDN,
99 if (sqlite3_bind_text(lsqlite3->queries.renameDN, column,
100 olddn, strlen(olddn),
101 SQLITE_STATIC) != SQLITE_OK) {
105 /* Bind new distinguished names */
106 column = sqlite3_bind_parameter_index(lsqlite3->queries.renameDN,
108 if (sqlite3_bind_text(lsqlite3->queries.renameDN, column,
109 newdn, strlen(newdn),
110 SQLITE_STATIC) != SQLITE_OK) {
114 /* Execute the query. This sets lsqlite3->last_rc */
115 SQL_EXEC(lsqlite3, renameDN, TRUE);
117 return lsqlite3->last_rc == 0 ? 0 : -1;
124 lsqlite3_delete(struct ldb_module *module,
129 struct lsqlite3_private * lsqlite3 = module->private_data;
131 /* ignore ltdb specials */
136 /* Bind distinguished names */
137 column = sqlite3_bind_parameter_index(lsqlite3->queries.deleteDN,
139 if (sqlite3_bind_text(lsqlite3->queries.deleteDN, column,
141 SQLITE_STATIC) != SQLITE_OK) {
145 /* Execute the query. This sets lsqlite3->last_rc */
146 SQL_EXEC(lsqlite3, deleteDN, TRUE);
148 return lsqlite3->last_rc == 0 ? 0 : -1;
152 * free a search result
155 lsqlite3_search_free(struct ldb_module *module,
156 struct ldb_message **res)
164 * add a single set of ldap message values to a ldb_message
167 lsqlite3_add_msg_attr(struct ldb_context *ldb,
168 struct ldb_message *msg,
170 struct berval **bval)
174 struct ldb_message_element * el;
176 count = ldap_count_values_len(bval);
182 el = talloc_realloc(msg, msg->elements, struct ldb_message_element,
183 msg->num_elements + 1);
191 el = &msg->elements[msg->num_elements];
193 el->name = talloc_strdup(msg->elements, attr);
201 el->values = talloc_array(msg->elements, struct ldb_val, count);
207 for (i=0;i<count;i++) {
208 el->values[i].data = talloc_memdup(el->values, bval[i]->bv_val, bval[i]->bv_len);
209 if (!el->values[i].data) {
212 el->values[i].length = bval[i]->bv_len;
222 * search for matching records
225 lsqlite3_search(struct ldb_module *module,
227 enum ldb_scope scope,
228 const char *expression,
229 const char * const *attrs,
230 struct ldb_message ***res)
234 struct ldb_context * ldb = module->ldb;
235 struct lsqlite3_private * lsqlite3 = module->private_data;
241 lsqlite3->last_rc = ldap_search_s(lsqlite3->ldap, base, (int)scope,
243 discard_const_p(char *, attrs),
245 if (lsqlite3->last_rc != LDAP_SUCCESS) {
249 count = ldap_count_entries(lsqlite3->ldap, ldapres);
250 if (count == -1 || count == 0) {
251 ldap_msgfree(ldapres);
255 (*res) = talloc_array(lsqlite3, struct ldb_message *, count+1);
257 ldap_msgfree(ldapres);
266 /* loop over all messages */
267 for (msg=ldap_first_entry(lsqlite3->ldap, ldapres);
269 msg=ldap_next_entry(lsqlite3->ldap, msg)) {
270 BerElement *berptr = NULL;
273 if (msg_count == count) {
274 /* hmm, got too many? */
275 ldb_debug(ldb, LDB_DEBUG_FATAL, "Fatal: ldap message count inconsistent\n");
279 (*res)[msg_count] = talloc(*res, struct ldb_message);
280 if (!(*res)[msg_count]) {
283 (*res)[msg_count+1] = NULL;
285 dn = ldap_get_dn(lsqlite3->ldap, msg);
290 (*res)[msg_count]->dn = talloc_strdup((*res)[msg_count], dn);
292 if (!(*res)[msg_count]->dn) {
297 (*res)[msg_count]->num_elements = 0;
298 (*res)[msg_count]->elements = NULL;
299 (*res)[msg_count]->private_data = NULL;
301 /* loop over all attributes */
302 for (attr=ldap_first_attribute(lsqlite3->ldap, msg, &berptr);
304 attr=ldap_next_attribute(lsqlite3->ldap, msg, berptr)) {
305 struct berval **bval;
306 bval = ldap_get_values_len(lsqlite3->ldap, msg, attr);
309 lsqlite3_add_msg_attr(ldb, (*res)[msg_count], attr, bval);
310 ldap_value_free_len(bval);
315 if (berptr) ber_free(berptr, 0);
320 ldap_msgfree(ldapres);
325 if (*res) lsqlite3_search_free(module, *res);
331 * Issue a series of SQL statements to implement the ADD/MODIFY/DELETE
332 * requests in the ldb_message
335 lsqlite3_msg_to_sql(struct ldb_context *ldb,
336 const struct ldb_message *msg,
343 sqlite3_stmt * stmt = NULL;
344 struct ldb_context * ldb = module->ldb;
345 struct lsqlite3_private * lsqlite3 = module->private_data;
347 for (i = 0; i < msg->num_elements; i++) {
348 const struct ldb_message_element *el = &msg->elements[i];
351 flags = LDB_FLAG_MOD_ADD;
353 flags = el->flags & LDB_FLAG_MOD_MASK;
356 /* Determine which query to use */
358 case LDB_FLAG_MOD_ADD:
359 stmt = lsqlite3->queries.addAttrValuePair;
362 case LDB_FLAG_MOD_DELETE:
363 stmt = lsqlite3->queries.deleteAttrValuePairs;
366 case LDB_FLAG_MOD_REPLACE:
367 stmt = lsqlite3->queries.replaceAttrValuePairs;
372 * All queries use dn id and attribute name. Bind them now.
375 /* Bind distinguished name id */
377 sqlite3_bind_parameter_index(
380 if (sqlite3_bind_int64(stmt,
382 dn_id) != SQLITE_OK) {
387 /* Bind attribute name */
389 sqlite3_bind_parameter_index(
392 if (sqlite3_bind_text(lsqlite3->queries.deleteDN, column,
393 el->name, strlen(el->name),
394 SQLITE_STATIC) != SQLITE_OK) {
400 /* For each value of the specified attribute name... */
401 for (j = 0; j < el->num_values; j++) {
403 /* ... bind the attribute value, if necessary */
405 case LDB_FLAG_MOD_ADD:
406 case LDB_FLAG_MOD_REPLACE:
407 /* Bind attribute value */
409 sqlite3_bind_parameter_index(
412 if (sqlite3_bind_text(
415 el->values[j].length,
416 SQLITE_STATIC) != SQLITE_OK) {
423 case LDB_FLAG_MOD_DELETE:
424 /* No additional parameters to this query */
428 /* Execute the query */
430 lsqlite3->last_rc = sqlite3_step(stmt);
431 (void) sqlite3_reset(stmt);
432 } while lsqlite3->last_rc == SQLITE_BUSY;
434 /* Make sure we succeeded */
435 if (lsqlite3->last_rc != SQLITE_OK) {
449 lsqlite3_add(struct ldb_module *module,
450 const struct ldb_message *msg)
453 struct ldb_context * ldb = module->ldb;
454 struct lsqlite3_private * lsqlite3 = module->private_data;
456 /* ignore ltdb specials */
457 if (msg->dn[0] == '@') {
461 /* Begin a transaction */
462 SQL_EXEC(lsqlite3, begin, TRUE);
464 /* This is a new DN. Bind new distinguished name */
465 column = sqlite3_bind_parameter_index(lsqlite3->queries.newDN, ":dn");
466 if (sqlite3_bind_text(lsqlite3->queries.newDN, column,
467 msg->dn, strlen(msg->dn),
468 SQLITE_STATIC) != SQLITE_OK) {
472 /* Add this new DN. This sets lsqlite3->last_rc */
473 SQL_EXEC(lsqlite3, newDN, TRUE);
475 if (lsqlite3->last_rc != SQLITE_DONE) {
479 /* Get the id of the just-added DN */
480 dn_id = sqlite3_last_insert_rowid(lsqlite3->sqlite3);
482 ret = lsqlite3_msg_to_sql(ldb, msg, dn_id, FALSE);
484 /* Did the attribute additions (if any) succeeded? */
487 /* Yup. Commit the transaction */
488 SQL_EXEC(lsqlite3, commit, TRUE);
492 /* Attribute addition failed. Rollback the transaction */
493 SQL_EXEC(lsqlite3, rollback, TRUE);
496 /* If everything succeeded, return success */
497 return lsqlite3->last_rc == SQLITE_DONE && ret == 0 ? 0 : -1;
505 lsqlite3_modify(struct ldb_module *module,
506 const struct ldb_message *msg)
509 struct ldb_context * ldb = module->ldb;
510 struct lsqlite3_private * lsqlite3 = module->private_data;
512 /* ignore ltdb specials */
513 if (msg->dn[0] == '@') {
517 /* Begin a transaction */
518 SQL_EXEC(lsqlite3, begin, TRUE);
520 /* Get the dn_id for the specified DN */
522 sqlite3_bind_parameter_index(
523 lsqlite3->queries.getDNID,
525 if (sqlite3_bind_text(lsqlite3->queries.getDNID,
527 msg->dn, strlen(msg->dn),
528 SQLITE_STATIC) != SQLITE_OK) {
532 /* Get the id of this DN. This sets lsqlite3->last_rc */
533 SQL_EXEC(lsqlite3, getDNID, FALSE);
535 if (lsqlite3->last_rc != SQLITE_ROW) {
539 dn_id = sqlite3_column_int64(lsqlite3->queries.getDNID,
541 (void) sqlite3_reset(lsqlite3->queries.getDNID);
543 ret = lsqlite3_msg_to_sql(ldb, msg, dn_id, FALSE);
545 /* Did the attribute additions (if any) succeeded? */
548 /* Yup. Commit the transaction */
549 SQL_EXEC(lsqlite3, commit, TRUE);
553 /* Attribute addition failed. Rollback the transaction */
554 SQL_EXEC(lsqlite3, rollback, TRUE);
557 /* If everything succeeded, return success */
558 return lsqlite3->last_rc == SQLITE_DONE && ret == 0 ? 0 : -1;
562 lsqlite3_lock(struct ldb_module *module,
563 const char *lockname)
566 struct ldb_context * ldb = module->ldb;
567 struct lsqlite3_private * lsqlite3 = module->private_data;
569 if (lockname == NULL) {
573 /* If we're already locked, just update lock count */
574 if (++lsqlite3->lock_count > 1) {
578 /* Write-lock (but not read-lock) the database */
579 SQL_EXEC(lsqlite3, begin, TRUE);
581 return lsqlite3->last_rc == 0 ? 0 : -1;
585 lsqlite3_unlock(struct ldb_module *module,
586 const char *lockname)
589 struct ldb_context * ldb = module->ldb;
590 struct lsqlite3_private * lsqlite3 = module->private_data;
592 if (lockname == NULL) {
596 /* If we're not already locked, there's nothing to do */
597 if (lsqlite3->lock_count == 0) {
601 /* Decrement lock count */
602 if (--lsqlite3->lock_count == 0) {
604 /* Final unlock. Unlock the database */
605 SQL_EXEC(lsqlite3, commit, TRUE);
608 return lsqlite3->last_rc == 0 ? 0 : -1;
612 * return extended error information
615 lsqlite3_errstring(struct ldb_module *module)
617 struct lsqlite3_private * lsqlite3 = module->private_data;
619 return sqlite3_errmsg(lsqlite3->sqlite3);
623 static const struct ldb_module_ops lsqlite3_ops = {
626 lsqlite3_search_free,
638 lsqlite3_destructor(void *p)
640 struct lsqlite3_private * lsqlite3 = p;
642 (void) sqlite3_close(lsqlite3->sqlite3);
647 lsqlite3_initialize(lsqlite3_private *lsqlite3,
650 int bNewDatabase = False;
655 const char * schema =
657 -- ------------------------------------------------------
659 PRAGMA auto_vacuum=1;
661 -- ------------------------------------------------------
665 -- ------------------------------------------------------
667 CREATE TABLE ldb_info AS
668 SELECT 'LDB' AS database_type,
671 CREATE TABLE ldb_distinguished_names
673 dn_id INTEGER PRIMARY KEY AUTOINCREMENT,
677 CREATE TABLE ldb_object_classes
679 class_name TEXT PRIMARY KEY,
681 max_child_num INTEGER
684 CREATE TABLE ldb_dn_object_classes
686 dn_id INTEGER REFERENCES ldb_distinguished_names,
687 class_name TEXT REFERENCES ldb_object_classes
690 CREATE TABLE ldb_attributes
692 attr_name TEXT PRIMARY KEY,
693 case_insensitive_p BOOLEAN DEFAULT FALSE,
694 wildcard_p BOOLEAN DEFAULT FALSE,
695 hidden_p BOOLEAN DEFAULT FALSE,
696 integer_p BOOLEAN DEFAULT FALSE
699 CREATE TABLE ldb_attr_value_pairs
701 dn_id INTEGER REFERENCES ldb_distinguished_names,
702 attr_name TEXT, -- optionally REFERENCES ldb_attributes
705 UNIQUE (dn_id, attr_name, attr_value)
708 -- ------------------------------------------------------
710 CREATE TRIGGER ldb_distinguished_names_delete_tr
712 ON ldb_distinguished_names
715 DELETE FROM ldb_attr_value_pairs
716 WHERE dn_id = old.dn_id;
717 DELETE FROM ldb_dn_object_classes
718 WHERE dn_id = old.dn_id;
721 CREATE TRIGGER ldb_attr_value_pairs_insert_tr
723 ON ldb_attr_value_pairs
726 INSERT OR IGNORE INTO ldb_attributes
732 CREATE TRIGGER ldb_attr_value_pairs_delete_tr
734 ON ldb_attr_value_pairs
737 DELETE FROM ldb_attributes
738 WHERE (SELECT COUNT(*)
739 FROM ldb_attr_value_pairs
740 WHERE attr_name = old.attr_name) = 0
741 AND attr_name = old.attr_name;
744 -- ------------------------------------------------------
746 CREATE INDEX ldb_distinguished_names_dn_idx
747 ON ldb_distinguished_names (dn);
749 CREATE INDEX ldb_object_classes_tree_key_idx
750 ON ldb_object_classes (tree_key);
753 CREATE INDEX ldb_dn_object_classes_dn_id_idx
754 ON ldb_dn_object_classes (dn_id);
756 CREATE INDEX ldb_dn_object_classes_class_name_idx
757 ON ldb_dn_object_classes (class_name);
760 CREATE INDEX ldb_attr_value_pairs_dn_id_name_case_idx
761 ON ldb_attr_value_pairs (dn_id, attr_name);
763 CREATE INDEX ldb_attr_value_pairs_dn_id_name_nocase_idx
764 ON ldb_attr_value_pairs (dn_id, attr_name COLLATE NOCASE);
766 -- ------------------------------------------------------
768 /* all defaults for dn, initially */
769 INSERT INTO ldb_attributes (attr_name)
772 /* We need an implicit 'top' level object class */
773 INSERT INTO ldb_object_classes (class_name, tree_key)
774 SELECT 'top', /* next_tree_key(NULL) */ '0001';
776 -- ------------------------------------------------------
780 -- ------------------------------------------------------
783 /* Skip protocol indicator of url */
784 if ((p = strchr(url, ':')) == NULL) {
785 return SQLITE_MISUSE;
791 * See if we'll be creating a new database, or opening an existing one
793 if ((stat(p, &statbuf) < 0 && errno == ENOENT) ||
794 statbuf.st_size == 0) {
799 /* Try to open the (possibly empty/non-existent) database */
800 if ((lsqlite3->last_rc = sqlite3_open(p, &lsqlite3->sqlite3)) != SQLITE_SUCCESS) {
806 * Create the database schema
808 for (pTail = schema; pTail != NULL; ) {
810 if ((lsqlite3->last_rc = sqlite3_prepare(
815 &pTail)) != SQLITE_SUCCESS ||
816 (lsqlite3->last_rc = sqlite3_step(stmt)) != SQLITE_DONE ||
817 (lsqlite3->last_rc = sqlite_finalize(stmt)) != SQLITE_SUCCESS) {
819 (void) sqlite3_close(lsqlite3->sqlite3);
825 * Ensure that the database we opened is one of ours
827 if ((lsqlite3->last_rc = sqlite3_prepare(
830 " FROM sqlite_master "
831 " WHERE type = 'table' "
835 " 'ldb_distinguished_names', "
836 " 'ldb_object_classes', "
837 " 'ldb_dn_object_classes', "
838 " 'ldb_attributes', "
839 " 'ldb_attr_value_pairs' "
843 &pTail)) != SQLITE_SUCCESS ||
844 (lsqlite3->last_rc = sqlite3_step(stmt)) != SQLITE_ROW ||
845 sqlite3_column_int(stmt, 0) != 6 ||
846 (lsqlite3->last_rc = sqlite_finalize(stmt)) != SQLITE_SUCCESS ||
848 (lsqlite3->last_rc = sqlite3_prepare(
852 " WHERE database_type = 'LDB' "
853 " AND version = '1.0';",
856 &pTail)) != SQLITE_SUCCESS ||
857 (lsqlite3->last_rc = sqlite3_step(stmt)) != SQLITE_ROW ||
858 (lsqlite3->last_rc = sqlite_finalize(stmt)) != SQLITE_SUCCESS) {
860 /* It's not one that we created. See ya! */
861 (void) sqlite3_close(lsqlite3->sqlite3);
862 return SQLITE_MISUSE;
867 * Pre-compile each of the queries we'll be using.
870 if ((lsqlite3->last_rc = sqlite3_prepare(
874 &lsqlite3->queries.begin,
875 &pTail)) != SQLITE_SUCCESS ||
877 (lsqlite3->last_rc = sqlite3_prepare(
881 &lsqlite3->queries.commit,
882 &pTail)) != SQLITE_SUCCESS ||
884 (lsqlite3->last_rc = sqlite3_prepare(
888 &lsqlite3->queries.rollback,
889 &pTail)) != SQLITE_SUCCESS ||
891 (lsqlite3->last_rc = sqlite3_prepare(
893 "INSERT INTO ldb_distinguished_names (dn_id, dn) "
894 " VALUES (:dn_id, :dn);",
896 &lsqlite3->queries.newDN,
897 &pTail)) != SQLITE_SUCCESS ||
899 (lsqlite3->last_rc = sqlite3_prepare(
901 "UPDATE ldb_distinguished_names "
903 " WHERE dn = :oldDN;",
905 &lsqlite3->queries.renameDN,
906 &pTail)) != SQLITE_SUCCESS ||
908 (lsqlite3->last_rc = sqlite3_prepare(
910 "DELETE FROM ldb_distinguished_names "
913 &lsqlite3->queries.deleteDN,
914 &pTail)) != SQLITE_SUCCESS ||
916 (lsqlite3->last_rc = sqlite3_prepare(
918 "INSERT OR IGNORE INTO ldb_object_classes "
919 " (class_name, tree_key)"
920 " SELECT :class_name, next_tree_key(NULL);",
922 &lsqlite3->queries.newObjectClass,
923 &pTail)) != SQLITE_SUCCESS ||
925 (lsqlite3->last_rc = sqlite3_prepare(
927 "INSERT OR REPLACE INTO ldb_dn_object_classes "
928 " (dn_id, class_name) "
929 " VALUES (:dn_id, :class_name);",
931 &lsqlite3->queries.assignObjectClass,
932 &pTail)) != SQLITE_SUCCESS ||
934 (lsqlite3->last_rc = sqlite3_prepare(
936 "INSERT OR IGNORE INTO ldb_attributes (name) "
939 &lsqlite3->queries.newAttributeUseDefaults,
940 &pTail)) != SQLITE_SUCCESS ||
942 (lsqlite3->last_rc = sqlite3_prepare(
944 "INSERT OR REPLACE INTO ldb_attributes "
946 " case_insensitive_p, "
951 " :case_insensitive_p, "
956 &lsqlite3->queries.newAttribute,
957 &pTail)) != SQLITE_SUCCESS ||
959 (lsqlite3->last_rc = sqlite3_prepare(
961 "INSERT INTO ldb_attr_value_pairs "
962 " (dn_id, attr_name, attr_value) "
963 " VALUES (:dn_id, :attr_name, :attr_value);",
965 &lsqlite3->queries.addAttrValuePair,
966 &pTail)) != SQLITE_SUCCESS ||
968 (lsqlite3->last_rc = sqlite3_prepare(
970 "UPDATE ldb_attr_value_pairs "
971 " SET attr_value = :attr_value "
972 " WHERE dn_id = :dn_id "
973 " AND attr_name = :attr_name;",
975 &lsqlite3->queries.addAttrValuePair,
976 &pTail)) != SQLITE_SUCCESS ||
978 (lsqlite3->last_rc = sqlite3_prepare(
980 "DELETE FROM ldb_attr_value_pairs "
981 " WHERE dn_id = :dn_id "
982 " AND attr_name = :attr_name;"
984 &lsqlite3->queries.deleteAttrValuePair,
985 &pTail)) != SQLITE_SUCCESS ||
987 (lsqlite3->last_rc = sqlite3_prepare(
989 "INSERT OR REPLACE INTO ldb_object_classes "
990 " (class_name, tree_key) "
991 " SELECT :child_class, next_tree_key(:parent_class);"
993 &lsqlite3->queries.insertSubclass,
994 &pTail)) != SQLITE_SUCCESS ||
996 (lsqlite3->last_rc = sqlite3_prepare(
999 " FROM ldb_distinguished_names "
1002 &lsqlite3->queries.getDNID,
1003 &pTail)) != SQLITE_SUCCESS) {
1005 (void) sqlite3_close(lsqlite3->sqlite3);
1009 return SQLITE_SUCCESS;
1013 * connect to the database
1015 struct ldb_context *
1016 lsqlite3_connect(const char *url,
1018 const char *options[])
1021 struct ldb_context * ldb = NULL;
1022 struct lsqlite3_private * lsqlite3 = NULL;
1024 ldb = talloc(NULL, struct ldb_context);
1030 lsqlite3 = talloc(ldb, struct lsqlite3_private);
1036 lsqlite3->sqlite3 = NULL;
1037 lsqlite3->options = NULL;
1038 lsqlite3->lock_count = 0;
1040 lsqlite3->last_rc = lsqlite3_initialize(&lsqlite3->sqlite3, url);
1041 if (lsqlite3->last_rc != SQLITE_SUCCESS) {
1045 talloc_set_destructor(lsqlite3, lsqlite3_destructor);
1047 ldb->modules = talloc(ldb, struct ldb_module);
1048 if (!ldb->modules) {
1052 ldb->modules->ldb = ldb;
1053 ldb->modules->prev = ldb->modules->next = NULL;
1054 ldb->modules->private_data = lsqlite3;
1055 ldb->modules->ops = &lsqlite3_ops;
1059 * take a copy of the options array, so we don't have to rely
1060 * on the caller keeping it around (it might be dynamic)
1062 for (i=0;options[i];i++) ;
1064 lsqlite3->options = talloc_array(lsqlite3, char *, i+1);
1065 if (!lsqlite3->options) {
1069 for (i=0;options[i];i++) {
1071 lsqlite3->options[i+1] = NULL;
1072 lsqlite3->options[i] =
1073 talloc_strdup(lsqlite3->options, options[i]);
1074 if (!lsqlite3->options[i]) {
1083 if (lsqlite3->sqlite3 != NULL) {
1084 (void) sqlite3_close(lsqlite3->sqlite3);