probcomp / bayeslite

BayesDB on SQLite. A Bayesian database table for querying the probable implications of data as easily as SQL databases query the data itself.
http://probcomp.csail.mit.edu/software/bayesdb
Apache License 2.0
922 stars 64 forks source link

bdb.execute(sql) fails but bdb.sql_execute(sql) succeeds on SELECT #484

Open fsaad opened 7 years ago

fsaad commented 7 years ago
    bdb = bayeslite.bayesdb_open('resources/gapminder.bdb')
    pairwise = query(bdb, 'SELECT name0, name1 FROM dependence;')
    for row in pairwise.values[:1]:
        name0, name1 = row
        sql = '''
            SELECT %s, %s FROM %s
        ''' % (
            sqlite3_quote_name(name0),
            sqlite3_quote_name(name1),
            sqlite3_quote_name('gapminder_t'))
        print sql
        frame = bdb.sql_execute(sql).fetchall()
        print frame

OK, but replacing the line

        frame = bdb.execute(sql).fetchall()

returns

AssertionError: Invalid select table: u'gapminder_t'
riastradh-probcomp commented 7 years ago

Can you share gapminder.bdb, or the results of the initial SELECT, or a SQL trace from this program?

fsaad commented 7 years ago

Saving another incarnation of this error using COUNT(*) for future reference, where bdb.execute complains

E           AssertionError: Invalid select table: u't'

but bdb.sql_execute is fine

                    qt = sqlite3_quote_name(table)
                    qc = sqlite3_quote_name(cmd.name)
                    cursor = bdb.execute(
                        'SELECT COUNT(*) FROM %s WHERE %s IS NOT NULL' %
                        (qt, qc))

The data is from test_csv.csv_data and qc is height.

riastradh-probcomp commented 7 years ago

Date: Wed, 18 Jan 2017 03:41:37 -0800 From: F Saad notifications@github.com

Saving another incarnation of this error using COUNT(*) for future reference, where bdb.execute complains

   E           AssertionError: Invalid select table: u't'

but bdb.sql_execute is fine

                       qt = sqlite3_quote_name(table)
                       qc = sqlite3_quote_name(cmd.name)
                       cursor = bdb.execute(
                           'SELECT COUNT(*) FROM %s WHERE %s IS NOT NULL' %
                           (qt, qc))

The data is from test_csv.csv_data and qc is height.

Interesting. Somehow a Unicode string is getting passed through, but as I recall BQL works exclusively in US-ASCII. The reason this assertion fires is that the select table is the Unicode string u't', not the byte string b't' (a.k.a. just 't' in Python 2).

riastradh-probcomp commented 7 years ago

What is query here?