SQLite
Note
This feature is available only with a License - Contact us for more details
The SQLite object is a wrapper to the SQLite database, with multi tasking support: when a second task wants to open the same file (via the open() function), a lock is added to make sure the different calls are handled properly.
object SQLite {
constructor SQLite('a name');
bool open( String filename );
close();
rows[] execSQL( string )
bool hasError();
string getLastErrorMsg();
}
- Object: SQLite('database')
var db = new SQLite('stations');
.execSQL
.execSQL( query )
.hasError
Returns true if the last SQL statement returned error.
.hasError()
.getLastErrorMsg
.getLastErrorMsg();
.open
.open('filename');
.close
.close();
Example
var db = new SQLite('base_frequencies');
if( !db.open('test.db')) {
print('cannot open/create database');
exit();
}
// create table
var sql = "create table IF NOT EXISTS qrg( id int primary key not null, name char(50))" ;
if( db.execSQL( sql ) === false ) {
print('SQL error:' + db.getLastErrorMsg() );
}
sql = "insert into qrg (id,name) values (1,'test')" ;
db.execSQL( sql ) ;
if( db.hasError() ) {
print('SQL error:' + db.getLastErrorMsg() );
exit();
}
var res = db.execSQL('select * from qrg order by name');
if( res.length > 0 ) {
for( i=0 ; i < res.length ; i++ ) {
var row = res[i] ;
print('Row' + i + ': id=' + row.id + ', name:' + row.name );
}
} else if( db.hasError()) {
print('SQL error:' + db.getLastErrorMsg() );
}
Last update: July 8, 2022