Force an update on sqlite_master to perform a syntax check for * partial index and CHECK constraint expressions. * Also, used to resolve scalar functions used by the dbtable */
| 2243 | * Also, used to resolve scalar functions used by the dbtable |
| 2244 | */ |
| 2245 | int sql_syntax_check(struct ireq *iq, struct dbtable *db) |
| 2246 | { |
| 2247 | int rc = 0; |
| 2248 | int resolve_rc = 0; |
| 2249 | sqlite3 *hndl = NULL; |
| 2250 | struct schema_mem sm = {0}; |
| 2251 | const char *temp = "select 1 from sqlite_master limit 1"; |
| 2252 | char *err = NULL; |
| 2253 | int got_curtran = 0; |
| 2254 | master_entry_t *ents = NULL; |
| 2255 | int nents = 0; |
| 2256 | |
| 2257 | if (!do_syntax_check(db)) { |
| 2258 | return rc; |
| 2259 | } |
| 2260 | |
| 2261 | sql_mem_init(NULL); |
| 2262 | thread_memcreate(INDEXES_THREAD_MEMORY); |
| 2263 | |
| 2264 | rc = create_sqlmaster_record(db, NULL); |
| 2265 | if (rc) { |
| 2266 | logmsg(LOGMSG_ERROR, "%s: failed to create sqlmaster record\n", |
| 2267 | __func__); |
| 2268 | sql_mem_shutdown(NULL); |
| 2269 | return -1; |
| 2270 | } |
| 2271 | ents = create_master_entry_array(&db, 1, thedb->view_hash, &nents); |
| 2272 | if (!ents) { |
| 2273 | logmsg(LOGMSG_ERROR, "%s: failed to create master entries\n", __func__); |
| 2274 | sql_mem_shutdown(NULL); |
| 2275 | return -1; |
| 2276 | } |
| 2277 | |
| 2278 | struct sqlclntstate clnt; |
| 2279 | start_internal_sql_clnt(&clnt); |
| 2280 | clnt.sql = (char *)temp; |
| 2281 | |
| 2282 | /* schema_mems is used to pass db->schema to is_comdb2_index_blob so we can |
| 2283 | * mark db->schema->ix_blob if the index expression has blob fields */ |
| 2284 | sm.sc = db->schema; |
| 2285 | clnt.verify_indexes = 1; |
| 2286 | clnt.schema_mems = &sm; |
| 2287 | |
| 2288 | struct sql_thread *sqlthd = start_sql_thread(); |
| 2289 | sql_get_query_id(sqlthd); |
| 2290 | clnt.debug_sqlclntstate = pthread_self(); |
| 2291 | sqlthd->clnt = &clnt; |
| 2292 | |
| 2293 | get_copy_rootpages_custom(sqlthd, ents, nents); |
| 2294 | |
| 2295 | destroy_sqlite_master(ents, nents); |
| 2296 | |
| 2297 | struct sqlthdstate thd = {0}; |
| 2298 | rc = sqlite3_open_serial("db", &hndl, &thd); |
| 2299 | if (rc) { |
| 2300 | logmsg(LOGMSG_ERROR, "%s: sqlite3_open failed\n", __func__); |
| 2301 | goto done; |
| 2302 | } |
no test coverage detected