text
stringlengths 0
828
|
---|
# EXECUTE THE SQL COMMAND |
try: |
if manyValueList == False: |
cursor.execute(sqlQuery) |
else: |
# cursor.executemany(sqlQuery, manyValueList) |
# INSET LARGE LISTS IN BATCHES TO STOP MYSQL SERVER BARFING |
batch = 100000 |
offset = 0 |
stop = 0 |
while stop == 0: |
thisList = manyValueList[offset:offset + batch] |
offset += batch |
a = len(thisList) |
cursor.executemany(sqlQuery, thisList) |
dbConn.commit() |
if len(thisList) < batch: |
stop = 1 |
except pymysql.Error as e: |
if e[0] == 1050 and 'already exists' in e[1]: |
log.info(str(e) + '\n') |
elif e[0] == 1062: |
# Duplicate Key error |
log.debug('Duplicate Key error: %s\n' % (str(e), )) |
message = ""duplicate key error"" |
elif e[0] == 1061: |
# Duplicate Key error |
log.debug('index already exists: %s\n' % (str(e), )) |
message = ""index already exists"" |
elif ""Duplicate entry"" in str(e): |
log.debug('Duplicate Key error: %s\n' % (str(e), )) |
message = ""duplicate key error"" |
elif ""Deadlock"" in str(e): |
i = 0 |
while i < 10: |
time.sleep(1) |
i += 1 |
try: |
if manyValueList == False: |
cursor.execute(sqlQuery) |
else: |
# cursor.executemany(sqlQuery, manyValueList) |
# INSET LARGE LISTS IN BATCHES TO STOP MYSQL SERVER |
# BARFING |
batch = 100000 |
offset = 0 |
stop = 0 |
while stop == 0: |
thisList = manyValueList[offset:offset + batch] |
offset += batch |
a = len(thisList) |
cursor.executemany(sqlQuery, thisList) |
dbConn.commit() |
if len(thisList) < batch: |
stop = 1 |
i = 20 |
except: |
pass |
if i == 10: |
log.error('Deadlock: %s\n' % (str(e), )) |
message = ""Deadlock error"" |
raise |
else: |
sqlQueryTrim = sqlQuery[:1000] |
message = 'MySQL write command not executed for this query: << %s >>\nThe error was: %s \n' % (sqlQuery, |
str(e)) |
if Force == False: |
log.error(message) |
raise |
else: |
log.info(message) |
return -1 |
except pymysql.Warning as e: |
log.info(str(e)) |
except Exception as e: |
if ""truncated"" in str(e): |
log.error('%s\n Here is the sqlquery:\n%s\n' % (str(e), sqlQuery)) |
if manyValueList: |
log.error('... and the values:\n%s\n' % (thisList, )) |
elif ""Duplicate entry"" in str(e): |
log.warning('Duplicate Key error: %s\n' % (str(e), )) |
message = ""duplicate key error"" |
else: |
sqlQuery = sqlQuery[:2000] |
log.error( |
'MySQL write command not executed for this query: << %s >>\nThe error was: %s \n' % |
(sqlQuery, str(e))) |
if Force == False: |
sys.exit(0) |
return -1 |
dbConn.commit() |
# CLOSE THE CURSOR |
cOpen = True |
count = 0 |
while cOpen: |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.