0

次のコードを実行するのに問題があります。明らかにこれらのステートメントはコードの一部です。

cursor.execute("select max(propernoun_SRNO) from tblauto_tagged")

starting_index = cursor.fetchone()[0]

if starting_index  == None :

    starting_index = 1

ending_index = int(starting_index) +len(s)

i = 0

for j in range(starting_index,ending_index):
    for i in range(0,len(s)):
        c.append(nnp_array_index_coloumn.count(i))
        add1 = add1 + c[i-1]
        add2 = add1 + c[i]
        cursor.execute("INSERT INTO tblauto_tagged(propernoun_SRNO,tagger,train,propernoun,propernoun_ID) VALUES (?,?,?,?,?)",(j,str(iput),str(corpora),str(nnp_array[add1:add2]),0))
        for item in nnp_array_index_coloumn:
            if item not in uniques:
                uniques.append(item)
                add1=0;add2=0

発生するエラーは

IntegrityError: ('23000', "[23000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.61-community]Duplicate entry '1' for key 'PRIMARY' (1062) (SQLExecDirectW)")

問題を解決するために別のユーザーによる以前の試みを読みましたが、私にとっては何もうまくいきませんでした。

mysql> repair table  tblauto_tagged;
+--------------------------------+--------+----------+---------------------------------    ------------------------+
| Table                          | Op     | Msg_type | Msg_text                                                   |
+--------------------------------+--------+----------+---------------------------------------------------------+
| collegedatabase.tblauto_tagged | repair | note     | The storage engine for the table     doesn't support repair |
+--------------------------------+--------+----------+---------------------------------------------------------+
1 row in set (0.00 sec) 

mysql> select * from tblauto_tagged;
Empty set (0.00 sec)

あなたの有益な提案の後、私は次のステートメントを使用しました

cursor.execute("INSERT INTO tblauto_tagged(tagger,train,propernoun,propernoun_ID) VALUES (?,?,?,?)",(str(iput),str(corpora),str(nnp_array[add1:add2]),0))

そして、私は別の問題に遭遇しました。確かに今日は私の日ではありません.私の問題をより明確にするために、いくつかの追加情報で質問を編集しています. 固有名詞_SRNO = 149までは問題なく動作します

 mysql> select propernoun_SRNO ,tagger, train,propernoun,propernoun_ID from tblauto_tagged where propernoun_SRNO =149;
+-----------------+--------+-------+------------------------------------------------------------------------------------------------------------+---------------+
| propernoun_SRNO | tagger | train | propernoun                                                                                                   | propernoun_ID |
+-----------------+--------+-------+------------------------------------------------------------------------------------------------------------+---------------+
|             149 | 1      | 1     | ['Wing', 'tank', 'Hopper', 'BU', 'crewmember', 'beam', 'injured', 'Drug', 'Serious', 'Marine', 'Incident'] |             0 |
+-----------------+--------+-------+------------------------------------------------------------------------------------------------------------+---------------+

そして、propernoun_SRNO = 150 の後、これが得られます。

mysql> select propernoun_SRNO ,tagger, train,propernoun,propernoun_ID from tblauto_tagged where propernoun_SRNO =150;
+-----------------+--------+-------+------------+---------------+
| propernoun_SRNO | tagger | train | propernoun | propernoun_ID |
+-----------------+--------+-------+------------+---------------+
|             150 | 1      | 1     | []         |             0 |
+-----------------+--------+-------+------------+---------------+
1 row in set (0.00 sec)

これは、propernoun_SRNO = 22201 までずっと続きます。

mysql> select max(propernoun_SRNO) from tblauto_tagged;
+----------------------+
| max(propernoun_SRNO) |
+----------------------+
|                22201 |
+----------------------+
1 row in set (0.00 sec)

mysql> select propernoun_SRNO ,tagger, train,propernoun,propernoun_ID from tblauto_tagged where propernoun_SRNO =22201;
+-----------------+--------+-------+------------+---------------+
| propernoun_SRNO | tagger | train | propernoun | propernoun_ID |
+-----------------+--------+-------+------------+---------------+
|           22201 | 1      | 1     | []         |             0 |
+-----------------+--------+-------+------------+---------------+
1 row in set (0.00 sec)

何が問題なのかはわかりませんが、専門家の意見が必要だと思います。前のコメントで述べたように、シーケンスを使用する必要があります。アドバイスをお願いします

4

1 に答える 1

0

zerkms のコメントを説明するには:propernoun_SRNOすでに使用されている主キー (間違いでなければ) の値を含む行を挿入しようとしています。

すべての新しい行をデータベースに挿入しようとしている場合は、主キーの値を指定しないでください。MySQL は、列が として設定されていると仮定して、自動的に計算する必要がありますAUTO_INCREMENT

既存の行をこれらの ID で置き換えようとしている場合は、REPLACE代わりに を使用INSERTするか、新しい行を挿入する前に既存の行を削除してください。

于 2012-09-13T23:31:22.330 に答える