Python mysql 默認轉義函數(shù),損壞查詢。原始查詢字符串如下。它工作正常,并根據(jù)需要向數(shù)據(jù)庫添加記錄INSERT IGNORE INTO state (`name`, `search_query`, `business_status`, `business_type`, `name_type`, `link`) VALUES ("test_name1", "test", "test_status", "test_b_typ", "test_n_typ", "test_link"), ("test_name2", "test", "test_status", "test_b_typ", "test_n_typ", "test_link")但是在使用功能 safe_sql = self.conn.escape_string(original_sql) safe_sql 將其轉義以使 sql Injection 安全之后,正在生成如下b'INSERT IGNORE INTO state (`name`, `search_query`, `business_status`, `business_type`, `name_type`, `link`) VALUES (\\"test_name1\\", \\"test\\", \\"test_status\\", \\"test_b_typ\\", \\"test_n_typ\\", \\"test_link\\"), (\\"test_name2\\", \\"test\\", \\"test_status\\", \\"test_b_typ\\", \\"test_n_typ\\", \\"test_link\\")'現(xiàn)在,如果我嘗試執(zhí)行 safe_sql,我會收到以下語法錯誤MySQLdb._exceptions.ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \'\\"test_name1\\", \\"test\\", \\"test_status\\", \\"test_b_typ\\", \\"test_n_typ\\", \\"tes\' at line 1')這讓我想知道,如果我使用的轉義功能損壞/不兼容,或者我沒有以正確的方式使用它?此外,我一次輸入數(shù)百條記錄,并且由于與運行數(shù)百次的準備好的語句相比,單個查詢的快速處理(我純粹假設),我正在創(chuàng)建一個大型查詢。
Python:Mysql Escape 函數(shù)生成損壞的查詢
30秒到達戰(zhàn)場
2022-06-07 17:05:48