From: paulr Date: Tue, 19 Apr 2011 07:51:14 +0000 (+1000) Subject: db store work X-Git-Url: http://git.pjr.cc/?a=commitdiff_plain;h=2df6aefe9a0933d1bd06f911894c88c719b5fbb7;p=glcas.git db store work --- diff --git a/lib/plugins/datastore.php b/lib/plugins/datastore.php new file mode 100644 index 0000000..ccaca5c --- /dev/null +++ b/lib/plugins/datastore.php @@ -0,0 +1,43 @@ +"; +} + +function ds_leftMenu() +{ + echo "i am a ds leftmenu"; +} + +function ds_contentUrls() +{ + $calls["needs_base_page"] = true; + $calls["content_pane_function"] = "ds_contentPane"; + $calls["left_menu_function"] = "ds_leftMenu"; + + return $calls; +} + +function ds_createDS($ds_name, $store_location) +{ + +} + +function ds_fileds($ds_name, $file_id, $file_name) +{ +} + +function ds_downloadAndStore($ds_name, $file_id, $file_name, $file_url) +{ + +} + +?> \ No newline at end of file diff --git a/lib/plugins/db.php b/lib/plugins/db.php index a337718..f19a1fa 100644 --- a/lib/plugins/db.php +++ b/lib/plugins/db.php @@ -25,17 +25,18 @@ function db_createDB() } // all columns end up as text -function db_createTable($tablename, $ncolumns) +function db_createTable($tablename) { $db = db_getDB(); $sql = "create table \"$tablename\" (\"".$tablename."_id\" INTEGER PRIMARY KEY AUTOINCREMENT"; - for($i=1; $i <= $ncolumns; $i++) { - $colname = "column_$i"; + for($i=1; $i < func_num_args(); $i++) { + $colname = func_get_arg($i); $sql .= ", $colname text"; } $sql .= ")"; + echo "sql: $sql\n"; $db->query($sql); } @@ -57,7 +58,7 @@ function db_selectData($tablename, $column, $value) { $db = db_getDB(); - $sql = "select * from \"$tablename\" where column_$column like '%$value%'"; + $sql = "select * from \"$tablename\" where $column like '%$value%'"; $res = $db->query($sql); $data = $res->fetchAll(); @@ -73,6 +74,15 @@ function db_deleteData($tablename, $column, $value) } +function db_updateData($tablename, $column, $newdata, $wherecol, $wheredata, $exact=true) +{ + $db = db_getDB(); + + if($exact) $sql = "update \"$tablename\" set $column='$newdata' where $wherecol='$wheredata'"; + else $sql = "update \"$tablename\" set $column='$newdata' where $wherecol like '$wheredata'"; + return $db->query($sql); +} + function db_deleteTable($tablename) { $db = db_getDB(); diff --git a/unittests/dbtest.php b/unittests/dbtest.php index 20491c9..4310202 100644 --- a/unittests/dbtest.php +++ b/unittests/dbtest.php @@ -2,9 +2,9 @@ require_once("../lib/lib.php"); -db_createTable("table1", 4); -db_createTable("table2", 4); -db_createTable("table3", 4); +db_createTable("table1", "data1", "data2", "data3", "data4"); +db_createTable("table2", "data1", "data2", "data3", "data4"); +db_createTable("table3", "data1", "data2", "data3", "data4"); if(db_tableExists("table1")) echo "table 1 exists - correct\n"; else echo "table 1 not exists - wrong\n"; @@ -27,7 +27,7 @@ $tabs = db_getTables(); print_r($tabs); // now try a select -$ret = db_selectData("table1", "1", "data1"); +$ret = db_selectData("table1", "data1", "data1"); echo "did select 1 on table1 and got:\n"; print_r($ret); if(isset($ret[0])) { diff --git a/var/config.php b/var/config.php index 8e63d25..48cd513 100644 --- a/var/config.php +++ b/var/config.php @@ -4,6 +4,6 @@ $GLOBAL_BASE_URL="/src/eclipse-workspace/glcas/www/"; $DB_URL="sqlite:$BASE_DIR/var/ds_store.db"; -global $GLOBAL_BASE_URL; +global $GLOBAL_BASE_URL, $DB_URL; ?> \ No newline at end of file