get_columnNames('LastUpdate', function (data) {if (data.length > 0) { // In data you also have columnNamesconsole.log("Table full");}else {console.log("Table empty");}});
而另一个:
function get_columnNames(tableName, callback) {myDb.transaction(function (transaction) {var query_exec = "SELECT name, sql FROM sqlite_master WHERE type='table' AND name ='" + tableName + "'";transaction.executeSql(query_exec, [], function (tx, results) {var columnNames = [];var len = results.rows.length;if (len>0){var columnParts = results.rows.item(0).sql.replace(/^[^\(]+\(([^\)]+)\)/g, '$1').split(','); ///// RegExfor (i in columnParts) {if (typeof columnParts[i] === 'string')columnNames.push(columnParts[i].split(" ")[0]);};callback(columnNames);}else callback(columnNames);});});}
class CPhoenixDatabase():def __init__(self, dbname):self.dbname = dbnameself.conn = sqlite3.connect(dbname)
def is_table(self, table_name):""" This method seems to be working now"""query = "SELECT name from sqlite_master WHERE type='table' AND name='{" + table_name + "}';"cursor = self.conn.execute(query)result = cursor.fetchone()if result == None:return Falseelse:return True
library(DBI)con <- dbConnect(RSQLite::SQLite(), ":memory:")# let us check if table iris exists in the databasedbExistsTable(con, "iris")### returns FALSE
# now let us create the table iris below,dbCreateTable(con, "iris", iris)# Again let us check if the table iris exists in the database,dbExistsTable(con, "iris")### returns TRUE