Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
[fix] rewrite trigger to meet sqlite trigger restrictions
Browse files Browse the repository at this point in the history
[update] update sqlite_win.json
  • Loading branch information
Stephen committed Mar 1, 2017
1 parent 961993d commit 0995c47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions modules/sqlite/src/sqlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,13 @@ static void sqlite_try_update_trigger(SQLITE_HANDLE_DATA * handleData, SQLITE_SO
}
sql_primary[strlen(sql_primary)-1] = '\0'; // remove last comma

SNPRINTF_S(sql_drop_trigger, BUFSIZE - 1, "DROP TRIGGER %s_size_control;", src_table->table);
SNPRINTF_S(sql_trigger, BUFSIZE - 1, "CREATE TRIGGER %s_size_control INSERT ON %s WHEN (select count(*) from %s)>%d\n"
"BEGIN\n"
"DELETE FROM %s WHERE (%s) IN (SELECT %s FROM %s ORDER BY DATETIME limit (select count(*) - %d from %s));\n"
"END;",
SNPRINTF_S(sql_drop_trigger, BUFSIZE - 1, "DROP TRIGGER %s_size_control;", src_table->table);
SNPRINTF_S(sql_trigger, BUFSIZE - 1, "CREATE TRIGGER %s_size_control INSERT ON %s WHEN (SELECT count(*) from %s)>%d\n"
"BEGIN\n"
"DELETE FROM %s WHERE rowid <= (SELECT max(rowid) - %d FROM %s);\n"
"END;",
src_table->table, src_table->table, src_table->table, src_table->limit,
src_table->table, sql_primary, sql_primary, src_table->table, src_table->limit, src_table->table
src_table->table, src_table->limit, src_table->table
);
sqlite_exec(handleData, sql_drop_trigger, 0);
sqlite_exec(handleData, sql_trigger, 0);
Expand Down
8 changes: 4 additions & 4 deletions samples/sqlite_sample/src/sqlite_win.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"loader": {
"name": "native",
"entrypoint": {
"module.path": "D:\\code\\azure-iot-gateway-sdk_1216\\build\\modules\\iothub\\Debug\\iothub.dll"
"module.path": "..\\..\\..\\modules\\iothub\\Debug\\iothub.dll"
}
},
"args": {
Expand All @@ -19,7 +19,7 @@
"loader": {
"name": "native",
"entrypoint": {
"module.path": "D:\\code\\azure-iot-gateway-sdk_1216\\build\\modules\\identitymap\\Debug\\identity_map.dll"
"module.path": "..\\..\\..\\modules\\identitymap\\Debug\\identity_map.dll"
}
},
"args": [
Expand All @@ -35,7 +35,7 @@
"loader": {
"name": "native",
"entrypoint": {
"module.path": "D:\\code\\azure-iot-gateway-sdk_0113\\build\\modules\\sqlite\\Debug\\sqlite.dll"
"module.path": "..\\..\\..\\modules\\sqlite\\Debug\\sqlite.dll"
}
},
"args": {
Expand Down Expand Up @@ -81,7 +81,7 @@
"loader": {
"name": "native",
"entrypoint": {
"module.path": "D:\\code\\azure-iot-gateway-sdk_0113\\build\\modules\\modbus_read\\Debug\\modbus_read.dll"
"module.path": "..\\..\\..\\modules\\modbus_read\\Debug\\modbus_read.dll"
}
},
"args": [
Expand Down

0 comments on commit 0995c47

Please sign in to comment.