SQLAlchemy文本参数绑定给出“?”

时间:2019-07-08 19:23:06

标签: python sqlalchemy

我正在将ODBC驱动程序17用于SQL Server

我有这个:

def login(self):
        bot = self.bot
        bot.get('www.google.com')
        time.sleep(1)
        email = bot.find_element_by_name('user[email]')
        password = bot.find_element_by_name('user[password]')
        email.clear()
        password.clear()
        email.send_keys(self.username)
        password.send_keys(self.password)
        password.send_keys(Keys.RETURN)
        time.sleep(1)
        mouse = Controller()
        mouse.position = (408, 333)
        mouse.click(Button.left, 1)
        time.sleep(2)

        while url_main == 'www.google.com':
        try:
            time.sleep(2)
        except:
            break

        def repeat():
            mouse.click(Button.left, 1) , time.sleep(1)
            mouse.position = (853, 323)
            mouse.click(Button.left, 1) , time.sleep(1)
            mouse.position = (902, 162)
            mouse.click(Button.left, 1) , time.sleep(0)

返回失败:

q = text('select top 10 * from :x')

conn.execute(q, x="mytable")

运行sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', '[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Must declare the table variable "@P1". (1087) (SQLExecDirectW)') [SQL: select top 10 * from ?] [parameters: ('mytable',)] 可以。

尝试q = test('select top 10 * from mytable')令我迷茫。

1 个答案:

答案 0 :(得分:0)

马丁(Martijin)的评论是正确的。绑定参数仅适用于数据。

q = text('select top 10 * from :x')

conn.execute(q, x="mytable")

无效。

但是,

q = text('select :x from mytable')

conn.execute(q, x="thing1")

有效。