Hello,
Im fighting with this anoying error in my databse module. My code looks 
like this:

var sqlite3 = require("node-sqlite3");
> var fs = require('fs');
>
> var init = function () {
>     var db = new sqlite3.Database("test.db", function() {
>         
>         fs.readFile('initDB.sql', function(err,data){
>             if(err) {
>                 console.error("Could not open file: %s", err);
>                 return;
>             }
>             
>             var query = data.toString('utf8');
>             var queries = query.split(";");
>         
>             for(var i=0; i<queries.length; i++) {
>                 if( i<queries.length-1 ) {
>                     db.run(queries[i], function(error) {
>                         if(error) {
>                             console.log("Query Error: "+error);
>                         }
>                     });
>                 }
>                 else {
>                     db.run(queries[i], function (error) {
>                         if(error) {    
>                             console.log("Query Error: "+error);
>                         }
>                         
>                         db.close();
>                     });
>                 }
>             }
>         });
>     });
> };
>
> exports.load_customers = function(response) {
>     init();
>     
>     var db = new sqlite3.Database("./assets/sql/test.db", function () {
>         db.all("SELECT name FROM sqlite_master WHERE type = 'table'", 
> function (error, records) {
>             for(var record in records) {
>                 response.write(record+": "+records[record]+"\n");
>                 for(var prop in records[record]) {
>                     response.write("\t"+prop+": 
> "+records[record][prop]+"\n");
>                 }
>             }
>             
>             response.end();
>             db.close();
>         });
>     });
> };
>

The query file initDB.sql is like this:

CREATE TABLE IF NOT EXISTS TemporaryAuthTokens (
>   authToken TEXT PRIMARY KEY NOT NULL UNIQUE,
>   expireDate NUMERIC NOT NULL);
>
> CREATE  TABLE IF NOT EXISTS User (
>   id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE  ,
>   login TEXT NOT NULL ,
>   pass TEXT NOT NULL ,
>   creationDate NUMERIC NOT NULL ,
>   authToken TEXT NULL REFERENCES TemporaryAuthTokens(authToken)
>   );
>

When I launch code with this query, sometimes I can see all the tables 
listed, sometimes only one and I get always this error:

Query Error: Error: SQLITE_MISUSE: unknown error

I've read that SQLITE_MISUSE occurs when SQLITE API is used unproperly. 
Could you help me, because I can't find whats wrong in this code.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to