summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot2014-02-25 19:00:23 +0100
committerroot2014-02-25 19:00:23 +0100
commit8f54d6bfe9c35cae2efe8d1850b02c51e3cae69d (patch)
treebb9500911881dd44ec4db26a78acc3d1300c6e60
parent9740b868aa482580388a08956dd4db16e1673f61 (diff)
parent4baee1f0a462bf9d3a7210f4c1ca44ca9c705da9 (diff)
downloadrandom-8f54d6bfe9c35cae2efe8d1850b02c51e3cae69d.tar.gz
database dir
-rw-r--r--database/README1
-rw-r--r--www/insertfile.php34
-rw-r--r--www/setup.php34
3 files changed, 58 insertions, 11 deletions
diff --git a/database/README b/database/README
new file mode 100644
index 0000000..10ca50c
--- /dev/null
+++ b/database/README
@@ -0,0 +1 @@
+# Do nothing here, use setup.php to create the database.
diff --git a/www/insertfile.php b/www/insertfile.php
index a8b000c..5e07130 100644
--- a/www/insertfile.php
+++ b/www/insertfile.php
@@ -1,19 +1,31 @@
<?
-$en_dic = "../blob/en_GB.dic";
-$test = "../blob/test";
+$dic = "../blob/en_GB.dic";
+$table = "english";
-//if($file = file($en_dic)){
-$file = file($test);
- echo "Inserted file <br>";
- echo count($file);
- echo "<br> " . $file . "<br>";
+$bool = false;
- for($i=0;$i<count($file);$i++){
- echo $file[$i];
+$db = new SQLite3("../database/dict.db");
+
+if($file = file($dic)){
+
+ $rows = count($file);
+ for($i=0;$i<$rows;$i++){
+ if(!$db->exec("
+ BEGIN TRANSACTION;
+ INSERT INTO " . $table " VALUES (NULL, " . $file[$i] . ");
+ COMMIT;
+ ")){
+ echo "Failure writing to the database at row" . $i ."!";
+ $bool = true;
+ break;
+ }
+ }
+
+ if(!$bool){
+ echo "Successfull transfered the file into the database.";
}
-/*} else {
+} else {
echo "No file found!";
}
-*/
diff --git a/www/setup.php b/www/setup.php
new file mode 100644
index 0000000..a4ab123
--- /dev/null
+++ b/www/setup.php
@@ -0,0 +1,34 @@
+<?
+
+$db = new SQLite3("../database/dict.db");
+
+foreach ($_GET as $name => $value) {
+ if(preg_match("/drop(ped)?/i",$name)){
+ $bool=true;
+ }
+}
+
+if($bool){
+ if($db->exec("
+ BEGIN TRANSACTION;
+ PRAGMA writable_schema = 1;
+ DELETE FROM sqlite_master WHERE type = 'table';
+ PRAGMA writable_schema = 0;
+ COMMIT;
+ VACUUM;")
+ ){
+ echo "dropped everything";
+ } else {
+ echo "error with database";
+ }
+} else {
+ if($db->exec("
+ BEGIN TRANSACTION;
+ CREATE TABLE IF NOT EXISTS english (id INTEGER PRIMARY KEY, word TEXT UIQUE);
+ COMMIT;")
+ ) {
+ echo "Success!";
+ } else {
+ echo "Failure!" ;
+ }
+}