本着测试驱动设计的精神,我想测试表是否在我的SQLite3数据库中正确创建。为此,我想通过SQL查询列出表名。
我用:
创建了表格public static void setupTables(){
try(Statement stmt = con.createStatement()) {
String sql_student = ("CREATE TABLE IF NOT EXISTS " + STUDENT_TABLE + "(\n "
+ ID + " integer PRIMARY KEY,\n "
+ FIRSTNAME + " text,\n "
+ LASTNAME + " text\n"
+ ");");
String sql_teacher = ("CREATE TABLE IF NOT EXISTS " + TEACHER_TABLE + "(\n "
+ ID + " integer PRIMARY KEY,\n "
+ FIRSTNAME + " text,\n "
+ LASTNAME + " text\n"
+ ");");
stmt.execute(sql_student);
stmt.execute(sql_teacher);
stmt.close();
}catch(Exception e){
e.printStackTrace();
}
}
我的测试需要什么查询?我是否需要关注订单,或者保证创建表的顺序是否始终以相同的顺序存储?
答案 0 :(得分:0)
1)SELECT name FROM my_db.sqlite_master where type='table';
2)SELECT name FROM sqlite_temp_master WHERE type='table';
3)对于临时表:SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND
TABLE_CATALOG='dbName'
希望它会有所帮助!
答案 1 :(得分:0)
您可以使用以下查询。
var a =document.querySelector("[id^='taTextElement']");
console.log(a);