Some DB Facts

From PlainOldWebserver

Jump to: navigation, search

Q: What is the name of created database and where is it stored in the file system ?

A: The name of the created database is "object_db.sqlite"

    var mydb = new pow_DB("object_db");

And its located the "data" directory that is at the same level as "htdocs" and "log" directory.

Q:What is 1 liner to create database ?

    var pdb = new pow_DB("object_db");

Q:What is 1 liner to open database access ?

A: Unsure, it seem that its handled automatically by the pow_DB() function (this.open). From investigating "io.js" in the package.

Q:What is 1 liner to close database access ?

A: Unsure, it seem that its handled automatically by the pow_DB() function (this.reset). From investigating "io.js" in the package.

Q: Also what version of sqlite is embedded v 2.0 or 3.0

A: Sqlite 3.0

Q: What and how should quotes be escaped inside. refer to examples below and in documentation they work on Mac OSX.

My test script mydb.sjs

<?sjs
   
      
// to create a new database file name is "object_db.sqlite"

var mydb = new pow_DB("object_db");

// creates table named "namevalue"  sqlite is not typed so no need
//to specify type for name and value
// id INTEGER PRIMARY KEY  makes id autoincrement

mydb.exec("CREATE TABLE namevalue (id INTEGER PRIMARY KEY, name,value)");
       
// insert statement , properly quoted            
mydb.exec("INSERT INTO namevalue (name, value) VALUES ( 'age', '39')");
              
//  select statement looks like it returns a Comman Sperated Value string
//  this is not yet confirmed.
       
var results = mydb.exec("SELECT * FROM namevalue");

//  just output's the results to the webpage        
document.write(results+"");
// please note if you don't add a string to the end of the results object it will fail 
// don't know why it works but it does. 
       
  ?>


Q: How do I stop inserts from failing when my data contains quotes ?

A: escape("all of your input string's content"), and unescape("all of your strings returned from your queries");

2007.04.07.02:14 by ebradley4: I tried running the examples on Windows XP using POW 0.10.0 on Firefox 2.0.0.3 installed in default location and no database was created. Then I applied the fix contributed by emchem. See the Bugs page for the fix listed under the pow_db.open() heading. The fix worked like a charm. Now my Firefox Sqlite Database Manager is fully operational on windows too.

Personal tools
Navigation