From: Jeremy Tan Date: Thu, 15 Aug 2013 01:13:01 +0000 (+0800) Subject: Remove SQLite approach X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=5bd6aced71333d0dc8d142f593073c68811e5435;p=matches%2FMCTX3420.git Remove SQLite approach --- diff --git a/testing/sqlite-approach/README.txt b/testing/sqlite-approach/README.txt deleted file mode 100644 index 8f2e398..0000000 --- a/testing/sqlite-approach/README.txt +++ /dev/null @@ -1,14 +0,0 @@ -Note: Should be discarded in favour of the fastcgi approach - -SQLite approach to interfacing with web frontend: - -*Main program reads in sensor data and updates the sqlite database - with this new data -*When sqlite.php is called, the database is queried, and the values returned - to the caller (format can be anything you like) -*You could have a main webpage, ie index.html -*Whenever you need to update the page, you use jQuery (or other method) - to call sqlite.php, which returns the data needed - -This works because SQLite allows concurrent access to the database -(or it should). \ No newline at end of file diff --git a/testing/sqlite-approach/db/data.db b/testing/sqlite-approach/db/data.db deleted file mode 100644 index 4d7095b..0000000 Binary files a/testing/sqlite-approach/db/data.db and /dev/null differ diff --git a/testing/sqlite-approach/testapp/test.c b/testing/sqlite-approach/testapp/test.c deleted file mode 100644 index cd6e850..0000000 --- a/testing/sqlite-approach/testapp/test.c +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include -#include -#include - -static void updateSensor(sqlite3* db, int id, int value); - -int main(int argc, char *argv[]) { - if (argc != 2) { - printf ("Usage: %s db_location\n", argv[0]); - return 1; - } - - sqlite3* db; - int ret; - - if (ret = sqlite3_open(argv[1], &db) != SQLITE_OK) { - printf("Error opening database: %s\n", - sqlite3_errstr(ret)); - return 1; - } - - sqlite3_stmt *statement; - char *query = "insert into sensors values(3,4)"; - if (ret = sqlite3_prepare(db, query, (int)strlen(query) + 1, &statement, NULL) != SQLITE_OK) { - printf("Error in query: %s\n", - sqlite3_errstr(ret)); - } - - sqlite3_step(statement); - sqlite3_finalize(statement); - - updateSensor(db, 44, 2332); - sqlite3_close(db); - return 0; -} - -static void updateSensor(sqlite3* db, int id, int value) { - char query[BUFSIZ]; - snprintf(query, BUFSIZ, "update sensors set value=%d where id=%d", value, id); - - //Needs error checking - int ret; - if (ret = sqlite3_exec(db, query, NULL, NULL, NULL) != SQLITE_OK) { - printf("Error: %s\n", sqlite3_errstr(ret)); - } - if (!sqlite3_changes(db)) { - printf("Record doesn't exist; creating!\n"); - snprintf(query, BUFSIZ, "insert into sensors values(%d, %d)", id, value); - sqlite3_exec(db, query, NULL, NULL, NULL); - } -} diff --git a/testing/sqlite-approach/www/sqlite.php b/testing/sqlite-approach/www/sqlite.php deleted file mode 100644 index bd8496e..0000000 --- a/testing/sqlite-approach/www/sqlite.php +++ /dev/null @@ -1,33 +0,0 @@ -open('../db/data.db'); - } - - function getSensorValue($id) - { - //needs error checking, but you get the idea - $ret = $this->query("select value from sensors where sensor_id={$id}"); - $row = $ret->fetchArray(SQLITE3_NUM); - return $row[0]; - } - } - - $db = new MyDB(); - if (!$db) { - echo $db->lastErrorMsg(); - } else { - echo "yay
\n"; - } - - $ret = $db->query('SELECT * from test'); - while ($row = $ret->fetchArray(SQLITE3_ASSOC)) { - echo "NUM = ". $row['num'] . "
\n"; - } - - echo "Sensor 1 value: " . $db->getSensorValue(1). "
\n"; - $db->close(); - -?> \ No newline at end of file