[tarantool-patches] [PATCH v2 02/11] box: move db->pShchema init to sql_init

Kirill Shcherbatov kshcherbatov at tarantool.org
Sat Jun 9 12:32:15 MSK 2018


As we are going to call parser on box.cfg() to recreate triggers
from SQL, we should initialize Schema as it used in sqlite3BeginTrigger.

Part of #3273.
---
 src/box/sql.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/box/sql.c b/src/box/sql.c
index 7379cb4..93fca68 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -77,11 +77,22 @@ sql_init()
 		panic("failed to initialize SQL subsystem");
 
 	assert(db != NULL);
+	/*
+	 * Initialize pSchema to use SQL parser on initialization:
+	 * e.g. Trigger objects (compiled from SQL on tuple
+	 * insertion in _trigger) need to refer it.
+	 */
+	db->pSchema = sqlite3SchemaCreate(db);
+	if (db->pSchema == NULL) {
+		sqlite3_close(db);
+		panic("failed to initialize SQL Schema subsystem");
+	}
 }
 
 void
 sql_load_schema()
 {
+	assert(db->pSchema != NULL);
 	int rc;
 	struct session *user_session = current_session();
 	int commit_internal = !(user_session->sql_flags
@@ -89,7 +100,6 @@ sql_load_schema()
 
 	assert(db->init.busy == 0);
 	db->init.busy = 1;
-	db->pSchema = sqlite3SchemaCreate(db);
 	rc = sqlite3InitDatabase(db);
 	if (rc != SQLITE_OK) {
 		sqlite3SchemaClear(db);
-- 
2.7.4





More information about the Tarantool-patches mailing list