0

MySQL と Postgres については知っていますが、MsSQL については知っていませんか? それ、どうやったら出来るの?

その上

cursor.execute("insert into data_AutoScale_DELHUB(AWB_Number,Weight,Length,Width,Height,Customer_Name,Scan_Time,Series_Flag) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" , data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7])
print cursor.query

戻ります'pyodbc.Cursor' object has no attribute 'query'

4

2 に答える 2

0

これが最善の方法かどうかはわかりませんが、おそらく最も簡単な方法です。実行前にクエリを印刷するだけです。

queryTxt = "bla bla bla に挿入"

queryTxt を出力

カーソル.execute(queryTxt)

于 2014-08-14T11:49:47.280 に答える
0

文字列に(挿入された)値も取得したいと思います。

verboseQuery()次のような関数(おそらく)を作成することをお勧めします。

def verboseQuery(query, *data):
    # See if the data matches up
    if(len(data) == query.count('?')):
        count = 0
        while(count != len(data)):
            # Replace the first occurrence of '?' with the first data point
            query = query.replace('?', str(data[count]), 1)
            count += 1

    # If the data did not match the query, return the original query,
    # otherwise, return the query we modified earlier
    return query

次に、次のことができます。

query = verboseQuery("insert into data_AutoScale_DELHUB(AWB_Number,Weight,Length,Width,Height,Customer_Name,Scan_Time,Series_F ag) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" , data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7])
print query
cursor.execute(query)

どちらが出力されますか: (if data = [0, 1, 2, 3, 4, 5, 6, 7])

insert into data_AutoScale_DELHUB(AWB_Number,Weight,Length,Width,Height,Customer_Name,Scan_Time,Series_F ag) VALUES (0, 1, 2, 3, 4, 5, 6, 7)
于 2014-08-15T12:07:04.747 に答える