home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Narzedzia
/
AIMP2
/
aimp_2.61.583.exe
/
$TEMP
/
YandexPackSetup.msi
/
fil95129609F13FE0D668146158593D164B
< prev
next >
Wrap
Text File
|
2010-07-12
|
2KB
|
83 lines
XB.Database = function() {
this._connection = null;
}
XB.Database.prototype.open = function XBDB_open(fileName) {
if (!fileName)
throw new Error("Filename is required");
this.close();
var dbFile = XB._base.application.directories.XBRoot;
dbFile.append(fileName);
var storageService = XB._Cc["@mozilla.org/storage/service;1"].getService(XB._Ci.mozIStorageService);
try {
this._connection = storageService.openDatabase(dbFile);
} catch(e) {
let journalDBFile = XB._base.application.directories.XBRoot;
journalDBFile.append(fileName + "-journal");
try { journalDBFile.remove(false); } catch(ex) {}
if (e.result == XB._Cr.NS_ERROR_FILE_CORRUPTED)
dbFile.remove(false);
this._connection = storageService.openDatabase(dbFile);
}
}
XB.Database.prototype.close = function XBDB_close() {
if (this._connection) {
try {
this._connection.close();
} catch(e) {}
this._connection = null;
}
}
XB.Database.prototype._createStatement = function XBDB__createStatement(query, parameters) {
let statement = this._connection.createStatement(query);
if (statement && !("executeAsync" in statement)) {
let wrappedStatement = XB._Cc["@mozilla.org/storage/statement-wrapper;1"].createInstance(XB._Ci.mozIStorageStatementWrapper);
wrappedStatement.initialize(statement);
statement = wrappedStatement;
}
if (parameters)
for (let name in parameters)
statement.params[name] = parameters[name];
return statement;
}
XB.Database.prototype.exec = function XBDB_exec(query, parameters) {
var statement,
result = [];
try {
statement = this._createStatement(query, parameters);
var columns = [];
for (var i = statement.columnCount; i--;)
columns.push(statement.getColumnName(i));
while (statement.step()) {
var row = {};
for (var i = columns.length; i--;)
row[columns[i]] = statement.row[columns[i]];
result.push(row);
}
} catch(e) {
XB._base.logger.error(e);
XB._base.logger.debug(e.stack);
} finally {
if (statement)
statement.reset();
}
return result;
}