Subj : Re: database object
To : Ragnarok
From : Tracker1
Date : Tue Apr 10 2007 11:34 am
Ragnarok wrote:
>>> db = new Sqlite("/tmp/tu_base.db");
>>> db.open();
>>> db.stmt = "CREATE TABLE prueba (field1 int , field2 varchar(100))";
>>> db.exec();
>>
>> Why not just db.exec("CREATE TABLE prueba (field1 int , field2
>> varchar(100))") ?
>
> now, it work as exec(query) too.
Suggestion for syntax...
var db = new Sqlite("/tmp/tu_base.db");
try {
db.open(); //throw an object when a connection fails...
var results = db.exec("CREATE TABLE ...");
//should return 0, no rows effected
results = db.query("SELECT ...");
results.rows <-- array of rows
results.columns <-- array of column titles
for (i in results.rows) {
results.rows[i]["columnName"]
...or...
results.rows[i][columnIndex]
}
} catch(dbError) {
console.write("ERROR: " + dbError.message + "\r\n\r\n");
}
Just a suggestion on this, to keep it easy enough to use the results...
a .exec() method which executes the query and returns the rows affected as the
result... a .query() method which returns a results object that has a rows
array defined (each row containing an associative array for columns, in
order)... as well as a columns array listing the column names..
results.rows.length could be used to determin a result count.
Have a DatabaseErrorObject that is thrown when an error state occurs, with a
.toString() and .Message properties for use in a result message.
--
Michael J. Ryan - tracker1(at)theroughnecks(dot)net - www.theroughnecks.net
icq: 4935386 - AIM/AOL: azTracker1 - Y!: azTracker1 - MSN/Win: (email)
---
� Synchronet � theroughnecks.net - you know you want it