Skip to content

Commit c77815e

Browse files
committed
Fix the tables and columns populating query.
When a table had a column by the same name, the column name was returned as null. eg: "create table t (t text)" would return the table name as t and column name as null.
1 parent 4ddffce commit c77815e

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

litecli/sqlexecute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class SQLExecute(object):
3232
table_columns_query = """
3333
SELECT m.name as tableName, p.name as columnName
3434
FROM sqlite_master m
35-
LEFT OUTER JOIN pragma_table_info((m.name)) p ON m.name <> p.name
35+
JOIN pragma_table_info((m.name)) p
3636
WHERE m.type IN ('table','view') AND m.name NOT LIKE 'sqlite_%'
3737
ORDER BY tableName, columnName
3838
"""

tests/test_sqlexecute.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ def test_binary(executor):
3838

3939

4040
## Failing in Travis for some unknown reason.
41-
# @dbtest
42-
# def test_table_and_columns_query(executor):
43-
# run(executor, "create table a(x text, y text)")
44-
# run(executor, "create table b(z text)")
45-
46-
# assert set(executor.tables()) == set([("a",), ("b",)])
47-
# assert set(executor.table_columns()) == set([("a", "x"), ("a", "y"), ("b", "z")])
41+
@dbtest
42+
def test_table_and_columns_query(executor):
43+
run(executor, "create table a(x text, y text)")
44+
run(executor, "create table b(z text)")
45+
run(executor, "create table t(t text)")
46+
47+
assert set(executor.tables()) == set([("a",), ("b",), ("t",)])
48+
assert set(executor.table_columns()) == set([("a", "x"), ("a", "y"), ("b", "z"), ("t", "t")])
49+
assert set(executor.table_columns()) == set([("a", "x"), ("a", "y"), ("b", "z"), ("t", "t")])
4850

4951

5052
@dbtest

0 commit comments

Comments
 (0)