Inuma Member Licensed User Nov 9, 2018 #1 I have a sql database with an unknown count of tables. How to find the number of tables in the database? For example I try: Code: Copy dim count_tables as Cursor count_tables= Main.sql1.ExecQuery("SELECT COUNT() FROM sqlite_master WHERE TYPE='table'") count_tables.Position=0 Msgbox("Tables",count_tables.GetInt(0)) but it returns error "column not exists"
I have a sql database with an unknown count of tables. How to find the number of tables in the database? For example I try: Code: Copy dim count_tables as Cursor count_tables= Main.sql1.ExecQuery("SELECT COUNT() FROM sqlite_master WHERE TYPE='table'") count_tables.Position=0 Msgbox("Tables",count_tables.GetInt(0)) but it returns error "column not exists"
Erel B4X founder Staff member Licensed User Longtime User Nov 9, 2018 #2 Correct code: Code: Copy Dim count_tables As ResultSet = sql.ExecQuery("SELECT COUNT() FROM sqlite_master WHERE TYPE='table'") count_tables.NextRow Log("Number of tables: " & count_tables.GetInt2(0)) count_tables.Close Upvote 0
Correct code: Code: Copy Dim count_tables As ResultSet = sql.ExecQuery("SELECT COUNT() FROM sqlite_master WHERE TYPE='table'") count_tables.NextRow Log("Number of tables: " & count_tables.GetInt2(0)) count_tables.Close
R RB Smissaert Well-Known Member Licensed User Longtime User Nov 10, 2018 #3 Erel said: Correct code: Code: Copy Dim count_tables As ResultSet = sql.ExecQuery("SELECT COUNT() FROM sqlite_master WHERE TYPE='table'") count_tables.NextRow Log("Number of tables: " & count_tables.GetInt2(0)) count_tables.Close Click to expand... This is a bit simpler: Code: Copy Sub CountTables Dim lCountTables As Long = SQL.ExecQuerySingleResult("select count(*) from sqlite_master where type = 'table'") Log("CountTables, lCountTables: " & lCountTables) End Sub RBS Upvote 0
Erel said: Correct code: Code: Copy Dim count_tables As ResultSet = sql.ExecQuery("SELECT COUNT() FROM sqlite_master WHERE TYPE='table'") count_tables.NextRow Log("Number of tables: " & count_tables.GetInt2(0)) count_tables.Close Click to expand... This is a bit simpler: Code: Copy Sub CountTables Dim lCountTables As Long = SQL.ExecQuerySingleResult("select count(*) from sqlite_master where type = 'table'") Log("CountTables, lCountTables: " & lCountTables) End Sub RBS
eps Expert Licensed User Longtime User Nov 10, 2018 #5 RB Smissaert said: This is a bit simpler: Code: Copy Sub CountTables Dim lCountTables As Long = SQL.ExecQuerySingleResult("select count(*) from sqlite_master where type = 'table'") Log("CountTables, lCountTables: " & lCountTables) End Sub RBS Click to expand... I would put the number in to an Int, but Long would more than suffice. There's no real need to put the asterisk in, I'd prefer a column_name in there, but it could throw an error if it no longer exists. It used to be accepted SQL practice, but then was frowned upon, but might work fine in this scenario but not in a 'normal' counting scenario, e.g. number of records in a specific table. Upvote 0
RB Smissaert said: This is a bit simpler: Code: Copy Sub CountTables Dim lCountTables As Long = SQL.ExecQuerySingleResult("select count(*) from sqlite_master where type = 'table'") Log("CountTables, lCountTables: " & lCountTables) End Sub RBS Click to expand... I would put the number in to an Int, but Long would more than suffice. There's no real need to put the asterisk in, I'd prefer a column_name in there, but it could throw an error if it no longer exists. It used to be accepted SQL practice, but then was frowned upon, but might work fine in this scenario but not in a 'normal' counting scenario, e.g. number of records in a specific table.