Separate monitoring function plugin
[platform/core/connectivity/stc-manager.git] / src / database / tables / table-restrictions.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * This file implements restrictions entity handler methods.
19  *
20  * @file        table-restrictions.c
21  */
22
23 #include "stc-db.h"
24 #include "db-internal.h"
25 #include "table-restrictions.h"
26
27 /* DELETE statements */
28 #define DELETE_RESTRICTIONS "DELETE FROM restrictions " \
29         " WHERE binpath = ? AND iftype = ? AND ifname = ? " \
30         " AND subscriber_id = ? AND roaming = ?"
31
32 /* SELECT statements */
33 #define SELECT_RESTRICTIONS "SELECT binpath, data_limit, " \
34         " iftype, rstn_type, roaming, ifname, subscriber_id, " \
35         " data_warn_limit, monthly_limit, weekly_limit, daily_limit, month_start_date, " \
36         " restriction_id FROM restrictions"
37
38 #define SELECT_RESTRICTIONS_PER_APP "SELECT binpath, data_limit, " \
39         " iftype, rstn_type, roaming, ifname, subscriber_id, " \
40         " data_warn_limit, monthly_limit, weekly_limit, daily_limit, month_start_date, " \
41         " restriction_id " \
42         " FROM restrictions INDEXED BY restrictions_index " \
43         " WHERE binpath = ?"
44
45 #define SELECT_RESTRICTION_TYPE "SELECT rstn_type " \
46         " FROM restrictions INDEXED BY restrictions_index " \
47         " WHERE binpath = ? AND iftype = ?"
48
49 #define SELECT_RESTRICTION_TYPE_SUBSCRIBER_ID "SELECT rstn_type " \
50         " FROM restrictions INDEXED BY restrictions_index " \
51         " WHERE binpath = ? AND iftype = ? AND subscriber_id = ?"
52
53 #define SELECT_RESTRICTION_ID "SELECT restriction_id FROM restrictions " \
54         " WHERE binpath = ? AND iftype = ? AND subscriber_id = ? AND " \
55         " roaming = ? AND ifname = ?"
56
57 /* UPDATE statement */
58 #define UPDATE_NET_RESTRICTIONS "UPDATE restrictions " \
59         " SET binpath = ?, data_limit = ?, iftype = ?, rstn_type = ?, " \
60         " roaming = ?, ifname = ?, subscriber_id = ?, data_warn_limit = ?, " \
61         " monthly_limit = ?, weekly_limit = ?, daily_limit = ? " \
62         " WHERE restriction_id = ?"
63
64 /* INSERT statement */
65 #define INSERT_NET_RESTRICTIONS "INSERT INTO restrictions " \
66         " (binpath, data_limit, iftype, rstn_type, " \
67         " roaming, ifname, subscriber_id, data_warn_limit, " \
68         " monthly_limit, weekly_limit, daily_limit, month_start_date) " \
69         " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
70
71 static void __finalize_delete(void);
72
73 #define PREPARE_DELETE(stm, query) do { \
74         rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \
75         if (rc != SQLITE_OK) { \
76                 stm = NULL; \
77                 __finalize_delete(); \
78                 STC_LOGE("Failed to prepare \"%s\"query" \
79                          , query); \
80                 return rc; \
81         } \
82 } while (0)
83
84 static void __finalize_select(void);
85
86 #define PREPARE_SELECT(stm, query) do { \
87         rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \
88         if (rc != SQLITE_OK) { \
89                 stm = NULL; \
90                 __finalize_select(); \
91                 STC_LOGE("Failed to prepare \"%s\"query" \
92                          , query); \
93                 return rc; \
94         } \
95 } while (0)
96
97 static void __finalize_update(void);
98
99 #define PREPARE_UPDATE(stm, query) do { \
100         rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \
101         if (rc != SQLITE_OK) { \
102                 stm = NULL; \
103                 __finalize_update(); \
104                 STC_LOGE("Failed to prepare \"%s\"query" \
105                          , query); \
106                 return rc; \
107         } \
108 } while (0)
109
110 static void __finalize_insert(void);
111
112 #define PREPARE_INSERT(stm, query) do { \
113         rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \
114         if (rc != SQLITE_OK) { \
115                 stm = NULL; \
116                 __finalize_insert(); \
117                 STC_LOGE("Failed to prepare \"%s\"query" \
118                          , query); \
119                 return rc; \
120         } \
121 } while (0)
122
123 #define FINALIZE(stm) do { \
124         if (stm) { \
125                 sqlite3_finalize(stm); \
126                 stm = NULL; \
127         } \
128 } while (0)
129
130 /* DELETE statements */
131 static sqlite3_stmt *delete_restrictions;
132
133 /* SELECT statements */
134 static sqlite3_stmt *select_restriction;
135 static sqlite3_stmt *select_restriction_per_app;
136 static sqlite3_stmt *select_restriction_type;
137 static sqlite3_stmt *select_restriction_type_subscriber_id;
138 static sqlite3_stmt *select_restriction_id;
139
140 /* REPLACE statements */
141 static sqlite3_stmt *update_net_restrictions;
142
143 /* INSERT statements */
144 static sqlite3_stmt *insert_net_restrictions;
145
146 static int __prepare_delete(sqlite3 *db)
147 {
148         __STC_LOG_FUNC_ENTER__;
149         int rc;
150         static int initialized;
151
152         if (initialized) {
153                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
154                 return SQLITE_OK; //LCOV_EXCL_LINE
155         }
156
157         PREPARE_DELETE(delete_restrictions, DELETE_RESTRICTIONS);
158
159         initialized = 1;
160         __STC_LOG_FUNC_EXIT__;
161         return rc;
162 }
163
164 static void __finalize_delete(void)
165 {
166         __STC_LOG_FUNC_ENTER__;
167
168         FINALIZE(delete_restrictions);
169
170         __STC_LOG_FUNC_EXIT__;
171 }
172
173 static int __prepare_select(sqlite3 *db)
174 {
175         __STC_LOG_FUNC_ENTER__;
176         int rc;
177         static int initialized;
178
179         if (initialized) {
180                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
181                 return SQLITE_OK; //LCOV_EXCL_LINE
182         }
183
184         PREPARE_SELECT(select_restriction, SELECT_RESTRICTIONS);
185         PREPARE_SELECT(select_restriction_per_app, SELECT_RESTRICTIONS_PER_APP);
186         PREPARE_SELECT(select_restriction_type, SELECT_RESTRICTION_TYPE);
187         PREPARE_SELECT(select_restriction_type_subscriber_id, SELECT_RESTRICTION_TYPE_SUBSCRIBER_ID);
188         PREPARE_SELECT(select_restriction_id, SELECT_RESTRICTION_ID);
189
190         initialized = 1;
191         __STC_LOG_FUNC_EXIT__;
192         return rc;
193 }
194
195 static void __finalize_select(void)
196 {
197         __STC_LOG_FUNC_ENTER__;
198
199         FINALIZE(select_restriction);
200         FINALIZE(select_restriction_per_app);
201         FINALIZE(select_restriction_type);
202         FINALIZE(select_restriction_type_subscriber_id);
203         FINALIZE(select_restriction_id);
204
205         __STC_LOG_FUNC_EXIT__;
206 }
207
208 static int __prepare_replace(sqlite3 *db)
209 {
210         __STC_LOG_FUNC_ENTER__;
211         int rc;
212         static int initialized;
213
214         if (initialized) {
215                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
216                 return SQLITE_OK; //LCOV_EXCL_LINE
217         }
218
219         PREPARE_UPDATE(update_net_restrictions, UPDATE_NET_RESTRICTIONS);
220
221         initialized = 1;
222         __STC_LOG_FUNC_EXIT__;
223         return rc;
224 }
225
226 static void __finalize_update(void)
227 {
228         __STC_LOG_FUNC_ENTER__;
229
230         FINALIZE(update_net_restrictions);
231
232         __STC_LOG_FUNC_EXIT__;
233 }
234
235 static int __prepare_insert(sqlite3 *db)
236 {
237         __STC_LOG_FUNC_ENTER__;
238         int rc;
239         static int initialized;
240
241         if (initialized) {
242                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
243                 return SQLITE_OK; //LCOV_EXCL_LINE
244         }
245
246         PREPARE_UPDATE(insert_net_restrictions, INSERT_NET_RESTRICTIONS);
247
248         initialized = 1;
249         __STC_LOG_FUNC_EXIT__;
250         return rc;
251 }
252
253 static void __finalize_insert(void)
254 {
255         __STC_LOG_FUNC_ENTER__;
256
257         FINALIZE(insert_net_restrictions);
258
259         __STC_LOG_FUNC_EXIT__;
260 }
261
262 stc_error_e table_restrictions_per_app(const gchar* app_id,
263                                        const table_restrictions_info_cb restriction_cb,
264                                        void *user_data)
265 {
266         __STC_LOG_FUNC_ENTER__;
267         table_restrictions_info data;
268         int rc;
269         stc_error_e error_code = STC_ERROR_NONE;
270         sqlite3_stmt *stmt = select_restriction_per_app;
271
272         if (!app_id) {
273                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
274                 return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
275         }
276
277         DB_ACTION(sqlite3_bind_text(stmt, 1, app_id, -1,
278                                     SQLITE_TRANSIENT));
279         data.app_id = (char *)app_id;
280
281         do {
282                 rc = sqlite3_step(stmt);
283
284                 memset(&data, 0, sizeof(data));
285
286                 switch (rc) {
287                 case SQLITE_DONE:
288                         break;
289                 case SQLITE_ROW:
290                         data.app_id = (char *)sqlite3_column_text(stmt, 0);
291                         data.data_limit = sqlite3_column_int64(stmt, 1);
292                         data.iftype = (stc_iface_type_e)sqlite3_column_int(stmt, 2);
293                         data.rstn_type =
294                                 (stc_rstn_type_e)sqlite3_column_int(stmt, 3);
295                         data.roaming = sqlite3_column_int(stmt, 4);
296                         data.ifname = (char *)sqlite3_column_text(stmt, 5);
297                         data.subscriber_id = (char *)sqlite3_column_text(stmt, 6);
298                         data.data_warn_limit = sqlite3_column_int64(stmt, 7);
299                         data.monthly_limit = sqlite3_column_int64(stmt, 8);
300                         data.weekly_limit = sqlite3_column_int64(stmt, 9);
301                         data.daily_limit = sqlite3_column_int64(stmt, 10);
302                         data.restriction_id = sqlite3_column_int64(stmt, 11);
303
304                         if (restriction_cb(&data, user_data) == STC_CANCEL)
305                                 rc = SQLITE_DONE; //LCOV_EXCL_LINE
306                         break;
307                 case SQLITE_ERROR:
308                 default:
309                         STC_LOGE("Failed to enumerate restrictions: %s\n", //LCOV_EXCL_LINE
310                                  sqlite3_errmsg(stc_db_get_database()));
311
312                         __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
313                         error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
314                 }
315         } while (rc == SQLITE_ROW);
316
317 handle_error:
318         sqlite3_reset(stmt);
319         __STC_LOG_FUNC_EXIT__;
320         return error_code;
321 }
322
323 API stc_error_e table_restrictions_foreach(const table_restrictions_info_cb restriction_cb,
324                                        void *user_data)
325 {
326         __STC_LOG_FUNC_ENTER__;
327         table_restrictions_info data;
328         int rc;
329         stc_error_e error_code = STC_ERROR_NONE;
330         sqlite3_stmt *stmt = select_restriction;
331
332         do {
333                 rc = sqlite3_step(stmt);
334
335                 memset(&data, 0, sizeof(data));
336
337                 switch (rc) {
338                 case SQLITE_DONE:
339                         break;
340                 case SQLITE_ROW:
341                         data.app_id = (char *)sqlite3_column_text(stmt, 0);
342                         data.data_limit = sqlite3_column_int64(stmt, 1);
343                         data.iftype = (stc_iface_type_e)sqlite3_column_int(stmt, 2);
344                         data.rstn_type =
345                                 (stc_rstn_type_e)sqlite3_column_int(stmt, 3);
346                         data.roaming = sqlite3_column_int(stmt, 4);
347                         data.ifname = (char *)sqlite3_column_text(stmt, 5);
348                         data.subscriber_id = (char *)sqlite3_column_text(stmt, 6);
349                         data.data_warn_limit = sqlite3_column_int64(stmt, 7);
350                         data.monthly_limit = sqlite3_column_int64(stmt, 8);
351                         data.weekly_limit = sqlite3_column_int64(stmt, 9);
352                         data.daily_limit = sqlite3_column_int64(stmt, 10);
353                         data.month_start_date = sqlite3_column_int(stmt, 11);
354                         data.restriction_id = sqlite3_column_int64(stmt, 12);
355
356                         if (restriction_cb(&data, user_data) == STC_CANCEL)
357                                 rc = SQLITE_DONE; //LCOV_EXCL_LINE
358                         break;
359                 case SQLITE_ERROR:
360                 default:
361                         STC_LOGE("Failed to enumerate restrictions: %s\n", //LCOV_EXCL_LINE
362                                  sqlite3_errmsg(stc_db_get_database()));
363
364                         __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
365                         error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
366                 }
367         } while (rc == SQLITE_ROW);
368
369         sqlite3_reset(stmt);
370         __STC_LOG_FUNC_EXIT__;
371         return error_code;
372 }
373
374 stc_error_e table_restrictions_get_restriction_type_subscriber_id(const char *app_id,
375                                                           stc_iface_type_e iftype,
376                                                           const char *subscriber_id,
377                                                           stc_rstn_type_e *type)
378 {
379         __STC_LOG_FUNC_ENTER__;
380         int error_code = STC_ERROR_NONE;
381         int ret;
382         bool state_subscriber_id = 0;
383
384         if (type == NULL) {
385                 STC_LOGE("Please provide valid argument!"); //LCOV_EXCL_LINE
386                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
387                 return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
388         }
389
390         *type = STC_RSTN_TYPE_UNKNOWN;
391         sqlite3_reset(select_restriction_type_subscriber_id);
392         sqlite3_reset(select_restriction_type);
393
394         if (subscriber_id == NULL) {
395                 state_subscriber_id = 0;
396                 DB_ACTION(sqlite3_bind_text(select_restriction_type, 1,
397                                             app_id ? app_id : "", -1,
398                                             SQLITE_STATIC));
399                 DB_ACTION(sqlite3_bind_int(select_restriction_type, 2,
400                                            iftype));
401                 ret = sqlite3_step(select_restriction_type);
402         } else {
403                 state_subscriber_id = 1;
404                 DB_ACTION(sqlite3_bind_text(select_restriction_type_subscriber_id, 1,
405                                             app_id ? app_id : "", -1,
406                                             SQLITE_STATIC));
407                 DB_ACTION(sqlite3_bind_int(select_restriction_type_subscriber_id, 2,
408                                            iftype));
409                 DB_ACTION(sqlite3_bind_text(select_restriction_type_subscriber_id, 3,
410                                             subscriber_id, -1, SQLITE_STATIC));
411                 ret = sqlite3_step(select_restriction_type_subscriber_id);
412         }
413
414         switch (ret) {
415         case SQLITE_DONE:
416                 break;
417         case SQLITE_ROW:
418                 if (state_subscriber_id)
419                         *type = (stc_rstn_type_e)sqlite3_column_int(select_restriction_type_subscriber_id, 0);
420                 else
421                         *type = (stc_rstn_type_e)sqlite3_column_int(select_restriction_type, 0);
422                 break;
423         case SQLITE_ERROR:
424         default:
425                 STC_LOGE("Can't perform sql query: %s\n", //LCOV_EXCL_LINE
426                          sqlite3_errmsg(stc_db_get_database()));
427                 error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
428         }
429
430 handle_error:
431         sqlite3_reset(select_restriction_type);
432         sqlite3_reset(select_restriction_type_subscriber_id);
433         return error_code;
434 }
435
436 stc_error_e table_restrictions_get_restriction_type(const char *app_id,
437                                                      stc_iface_type_e iftype,
438                                                      stc_rstn_type_e *type)
439 {
440         __STC_LOG_FUNC_ENTER__;
441         __STC_LOG_FUNC_EXIT__;
442         return table_restrictions_get_restriction_type_subscriber_id(app_id, iftype,
443                                                              NULL, type);
444 }
445
446 stc_error_e table_restrictions_delete(const char *app_id,
447                                       const stc_iface_type_e iftype,
448                                       const char *ifname,
449                                       const char *subscriber_id,
450                                       const stc_roaming_type_e roaming)
451 {
452         stc_error_e error_code = STC_ERROR_NONE;
453         sqlite3_stmt *stmt = delete_restrictions;
454
455         STC_LOGD("app_id[%s] iftype[%d] ifname[%s] subscriber_id[%s] roaming[%d]",
456                  app_id, iftype, ifname, subscriber_id, roaming);
457
458         DB_ACTION(sqlite3_bind_text(stmt, 1, app_id ? app_id : "",
459                                     -1, SQLITE_TRANSIENT));
460         DB_ACTION(sqlite3_bind_int(stmt, 2, iftype));
461         DB_ACTION(sqlite3_bind_text(stmt, 3, ifname ? ifname : "",
462                                     -1, SQLITE_TRANSIENT));
463         DB_ACTION(sqlite3_bind_text(stmt, 4, subscriber_id ? subscriber_id : "",
464                                         -1, SQLITE_TRANSIENT));
465         DB_ACTION(sqlite3_bind_int(stmt, 5, roaming));
466
467         if (sqlite3_step(stmt) != SQLITE_DONE) {
468                 STC_LOGE("Failed to remove restrictions by network interface %s\n", //LCOV_EXCL_LINE
469                          sqlite3_errmsg(stc_db_get_database()));
470                 error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
471                 goto handle_error; //LCOV_EXCL_LINE
472         }
473
474         STC_LOGD("Restriction deleted for app_id [%s]", app_id);
475
476 handle_error:
477
478         sqlite3_reset(stmt);
479         return error_code;
480 }
481
482 stc_error_e __get_restriction_id(table_restrictions_info *info)
483 {
484         __STC_LOG_FUNC_ENTER__;
485         int rc;
486         stc_error_e error_code = STC_ERROR_NONE;
487         sqlite3_stmt *stmt = select_restriction_id;
488
489         DB_ACTION(sqlite3_bind_text(stmt, 1, info->app_id ? info->app_id : "",
490                                     -1, SQLITE_TRANSIENT));
491         DB_ACTION(sqlite3_bind_int(stmt, 2, info->iftype));
492         DB_ACTION(sqlite3_bind_text(stmt, 3, info->subscriber_id ? info->subscriber_id : "",
493                                     -1, SQLITE_TRANSIENT));
494         DB_ACTION(sqlite3_bind_int(stmt, 4, info->roaming));
495         DB_ACTION(sqlite3_bind_text(stmt, 5, info->ifname ? info->ifname : "",
496                                     -1, SQLITE_TRANSIENT));
497
498         rc = sqlite3_step(stmt);
499
500         switch (rc) {
501         case SQLITE_DONE:
502                 break;
503         case SQLITE_ROW:
504                 info->restriction_id = sqlite3_column_int64(stmt, 0);
505                 STC_LOGD("restriction id [%llu]", info->restriction_id);
506                 break;
507         case SQLITE_ERROR:
508         default:
509                 STC_LOGE("Failed to get restriction id: %s\n", //LCOV_EXCL_LINE
510                          sqlite3_errmsg(stc_db_get_database()));
511         }
512
513 handle_error:
514         sqlite3_reset(stmt);
515         __STC_LOG_FUNC_EXIT__;
516         return error_code;
517 }
518
519 stc_error_e table_restrictions_update(table_restrictions_info *info)
520 {
521         stc_error_e error_code = STC_ERROR_NONE;
522         sqlite3_stmt *stmt = insert_net_restrictions;
523
524         if (!info) {
525                 error_code = STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
526                 goto handle_error; //LCOV_EXCL_LINE
527         }
528
529         __get_restriction_id(info);
530         if (info->restriction_id)
531                 stmt = update_net_restrictions;
532
533         DB_ACTION(sqlite3_bind_text(stmt, 1, info->app_id ? info->app_id : "",
534                                     -1, SQLITE_TRANSIENT));
535         DB_ACTION(sqlite3_bind_int64(stmt, 2, info->data_limit));
536         DB_ACTION(sqlite3_bind_int(stmt, 3, info->iftype));
537         DB_ACTION(sqlite3_bind_int(stmt, 4, info->rstn_type));
538         DB_ACTION(sqlite3_bind_int(stmt, 5, info->roaming));
539         DB_ACTION(sqlite3_bind_text(stmt, 6, info->ifname ? info->ifname : "",
540                                     -1, SQLITE_TRANSIENT));
541         DB_ACTION(sqlite3_bind_text(stmt, 7, info->subscriber_id ? info->subscriber_id : "",
542                                     -1, SQLITE_TRANSIENT));
543         DB_ACTION(sqlite3_bind_int64(stmt, 8, info->data_warn_limit));
544         DB_ACTION(sqlite3_bind_int64(stmt, 9, info->monthly_limit));
545         DB_ACTION(sqlite3_bind_int64(stmt, 10, info->weekly_limit));
546         DB_ACTION(sqlite3_bind_int64(stmt, 11, info->daily_limit));
547
548         if (info->restriction_id)
549                 DB_ACTION(sqlite3_bind_int64(stmt, 12, info->restriction_id));
550         else
551                 DB_ACTION(sqlite3_bind_int64(stmt, 12, info->month_start_date));
552
553         if (sqlite3_step(stmt) != SQLITE_DONE) {
554                 STC_LOGE("Failed to set network restriction: %s\n", //LCOV_EXCL_LINE
555                          sqlite3_errmsg(stc_db_get_database()));
556                 error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
557                 goto handle_error; //LCOV_EXCL_LINE
558         }
559
560         if (info->restriction_id) {
561                 STC_LOGD("Restriction updated app_id [%s]", info->app_id);
562         } else {
563                 STC_LOGD("Restriction inserted app_id [%s]", info->app_id);
564                 __get_restriction_id(info);
565         }
566
567 handle_error:
568         sqlite3_reset(stmt);
569         return error_code;
570 }
571
572 stc_error_e table_restrictions_prepare(sqlite3 *db)
573 {
574         __STC_LOG_FUNC_ENTER__;
575
576         stc_error_e error_code = STC_ERROR_NONE;
577
578         if (db == NULL) {
579                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
580                 return STC_ERROR_FAIL; //LCOV_EXCL_LINE
581         }
582
583         DB_ACTION(__prepare_delete(db));
584         DB_ACTION(__prepare_select(db));
585         DB_ACTION(__prepare_replace(db));
586         DB_ACTION(__prepare_insert(db));
587
588 handle_error:
589
590         __STC_LOG_FUNC_EXIT__;
591         return error_code;
592 }
593
594 void table_restrictions_finalize(void)
595 {
596         __STC_LOG_FUNC_ENTER__;
597         __finalize_delete();
598         __finalize_select();
599         __finalize_update();
600         __finalize_insert();
601         __STC_LOG_FUNC_EXIT__;
602 }