Add Zotero.DB.columnExists(table, column)
This commit is contained in:
parent
b0e065a4ae
commit
6bcc8af86b
2 changed files with 23 additions and 0 deletions
|
@ -799,6 +799,14 @@ Zotero.DBConnection.prototype.tableExists = Zotero.Promise.coroutine(function* (
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Zotero.DBConnection.prototype.columnExists = async function (table, column) {
|
||||||
|
await this._getConnectionAsync();
|
||||||
|
var sql = `SELECT COUNT(*) FROM pragma_table_info(?) WHERE name=?`;
|
||||||
|
var count = await this.valueQueryAsync(sql, [table, column]);
|
||||||
|
return !!count;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse SQL string and execute transaction with all statements
|
* Parse SQL string and execute transaction with all statements
|
||||||
*
|
*
|
||||||
|
|
|
@ -341,4 +341,19 @@ describe("Zotero.DB", function() {
|
||||||
assert.ok(callback2Ran);
|
assert.ok(callback2Ran);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
describe("#columnExists()", function () {
|
||||||
|
it("should return true if a column exists", async function () {
|
||||||
|
assert.isTrue(await Zotero.DB.columnExists('items', 'itemID'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return false if a column doesn't exists", async function () {
|
||||||
|
assert.isFalse(await Zotero.DB.columnExists('items', 'foo'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return false if a table doesn't exists", async function () {
|
||||||
|
assert.isFalse(await Zotero.DB.columnExists('foo', 'itemID'));
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue