Я пытаюсь обновить мою базу данных с помощью файла Excel, но я нахожу эту ошибку при запуске приложения, я думаю, что проблема в синтаксисе запроса, я не уверен, какой правильный синтаксис для sqlAlchemy Query как Я не нашел ссылку для этого ...
Вот ошибка выглядит следующим образом:
Traceback (most recent call last):
File "D:/Tooling/20200206/MyDB_Update.py", line 21, in <module>
if(Add_To_DB.remove_duplicates(item,myCursor, myDB)):
File "D:\Tooling\20200206\MyDB.py", line 22, in remove_duplicates
mycursor.execute(sql, value)
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near ','. (102) (SQLExecDirectW); [42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Statement(s) could not be prepared. (8180)")
Process finished with exit code 1
и вот мое SQL соединение .py
from sqlalchemy import create_engine
class Add_To_DB():
# connect db
mydb = create_engine('mssql+pyodbc://WWX542337CDCD\SMARTRNO_EXPRESS/myDB?driver=SQL+Server+Native+Client+11.0')
mycursor = mydb.raw_connection().cursor()
def remove_duplicates(comp_zip, mycursor, mydb):
# fetching the column from database
flag = False
sql = "SELECT GBSC,SiteName,CellCI,CellLAC,CellName,CellIndex FROM [myDB].[dbo].[mnm_rotterdam_5_daily_details-20191216081027] WHERE (GBSC=? and SiteName=?, CellCI =? ,CellLAC=?,CellName=?,CellIndex=?); "
GBSC = comp_zip[0]
Site_Name = comp_zip[1],
Cell_CI = comp_zip[2],
cell_LAC = comp_zip[3]
cell_name = comp_zip[4],
cell_index = comp_zip[5],
value = (GBSC, Site_Name, Cell_CI, cell_LAC, cell_name, cell_index)
mycursor.execute(sql, value)
myresult = mycursor.fetchall()
if (myresult):
# print("title URL already exists")
flag = True
return (flag)
else:
# print("title URL dosen't exist")
return (flag)
def insert_into_db(insert_zip, mycursor, mydb):
sql = "Insert into [myDB].[dbo].[mnm_rotterdam_5_daily_details-20191216081027] (GBSC,SiteName,CellCI,CellLAC,CellName,CellIndex) values (?,?,?,?,?,?)"
GBSC = insert_zip[0]
Site_Name = insert_zip[1],
Cell_CI = insert_zip[2],
cell_LAC = insert_zip[3]
cell_name = insert_zip[4],
cell_index = insert_zip[5],
value = (GBSC, Site_Name, Cell_CI, cell_LAC, cell_name, cell_index)
mycursor.execute(sql, value)
return 'Added'
и это мой код функции обновления .py
from sqlalchemy import create_engine
import pandas as pd
from DB import Add_To_DB
mydb = create_engine(
'mssql+pyodbc://WWX542337CDCD\SMARTRNO_EXPRESS/myDB?driver=SQL+Server+Native+Client+11.0') # name of database
mycursor = mydb.raw_connection().cursor()
myDB = Add_To_DB.mydb
myCursor = Add_To_DB.mycursor
df = pd.read_excel('MNM_Rotterdam_5_Daily_Details-20191216081027.xlsx',sheet_name='GSM Details')
print(df)
date=df['Date']
GBSC=df['GBSC']
Site_Name=df['Site Name']
Cell_CI=df['Cell CI']
cell_LAC=df['Cell LAC']
cell_name=df['Cell Name']
cell_index=df['CellIndex']
comp_zip=zip(GBSC,Site_Name,Cell_CI,cell_LAC,cell_name,cell_index)
for item in comp_zip:
if(Add_To_DB.remove_duplicates(item,myCursor, myDB)):
continue#if data already then flag is true and not insert into db
Add_To_DB.insert_into_db(item,myCursor, myDB)
# ##write insert function here
, и это мой запрос на вставку:
sql = "Insert into [myDB].[dbo].[mnm_rotterdam_5_daily_details-20191216081027] (GBSC,SiteName,CellCI,CellLAC,CellName,CellIndex) values (?,?,?,?,?,?)"
, и это мой запрос на выбор
sql = "SELECT GBSC,SiteName,CellCI,CellLAC,CellName,CellIndex FROM [myDB].[dbo].[mnm_rotterdam_5_daily_details-20191216081027] WHERE (GBSC=? and SiteName=?, CellCI =? ,CellLAC=?,CellName=?,CellIndex=?); "
и это мой запрос к БД. Похоже:
SELECT *
,[Date]
,[GBSC]
,[BSCIndex]
,[SiteName]
,[CellCI]
,[CellLAC]
,[CellName]
,[CellIndex]
,[SiteName.1]
,[Voice_SetupFailRate_2G]
,[Voice_DropRate_2G]
,[OutgHandover_SuccesRate_2G]
,[Packet_SetupFailRate_2G]
,[Voice_ErlHr_2G]
,[Voice_ErlHr_2G_Daily]
,[Packet_DLMBytes_2G]
,[Packet_ULMBytes_2G]
,[Availability_2G]
,[Availability_2G_Cluster]
,[K3001:FailedSDCCHSeizuresduetoBusySDCCH]
,[K3000:SDCCHSeizureRequests]
,[CM30:CallDropsonSDCCH]
,[CA3030J:CallSetupIndications(SDCCH)(CircuitService)]
,[CA313:SuccessfulAssignments]
,[CA310:AssignmentRequests]
,[CM33:CallDropsonTrafficChannel]
,[CM3302:CallDropsonTrafficChannelinStableState(ReleaseIndication)]
,[A03701:NormalSpeechDisconnections]
,[A9103:NumberofFailedDownlinkGPRSTBFEstablishmentsduetoNoChannel]
,[A9303:NumberofFailedDownlinkEGPRSTBFEstablishmentsduetoNoChannel]
,[A9104:NumberofFailedDownlinkGPRSTBFEstablishmentsduetoMSNoResponse]
,[A9304:NumberofFailedDownlinkEGPRSTBFEstablishmentsduetoMSNoResponse]
,[A9101:NumberofDownlinkGPRSTBFEstablishmentAttempts]
,[A9301:NumberofDownlinkEGPRSTBFEstablishmentAttempts]
,[CH313:NumberofSuccessfulOutgoingInternalInter-CellHandovers]
,[CH333:SuccessfulOutgoingExternalInter-CellHandovers]
,[CH311:NumberofOutgoingInternalInter-CellHandoverCommands]
,[CH331:OutgoingExternalInter-CellHandoverCommands]
,[K3014:TrafficVolumeonTCH(Erl)]
,[TR373:CellAvailability(%)]
,[K3011A:FailedTCHSeizuresduetoBusyTCH(TrafficChannel)]
,[K3011B:FailedTCHSeizuresinTCHHandoversduetoBusyTCH(TrafficChannel)]
,[K3034:TCHHTrafficVolume(Erl)]
,[K3004:TrafficVolumeonSDCCH(Erl)]
,[AR9311:AverageNumberofOccupiedPDCHs]
,[K3010A:TCHSeizureRequests(TrafficChannel)]
,[CM30C:CallDropsonSDCCH(CallType)]
,[ZTR104B:CallDropRateonSDCCH(CallType)(%)]
,[K3003A:SuccessfulSDCCHSeizures(CallType)]
,[K3005:AvailableSDCCHs]
,[K3006:ConfiguredSDCCHs]
,[K3016:ConfiguredTCHs]
,[K3015:AvailableTCHs]
,[TCHTrafficVolumeperChannel(Erl)]
,[M3030A:CallDropsonTCH(TA)]
,[M3030B:CallDropsonTCH(UplinkReceivedLevel)]
,[M3030C:CallDropsonTCH(DownlinkReceivedLevel)]
,[M3030D:CallDropsonTCH(UplinkandDownlinkReceivedLevel)]
,[M3030E:CallDropsonTCH(UplinkFER)]
,[M3030F:CallDropsonTCH(DownlinkFER)]
,[M3030G:CallDropsonTCH(UplinkandDownlinkFER)]
,[M3030H:CallDropsonTCH(UplinkQuality)]
,[M3030I:CallDropsonTCH(DownlinkQuality)]
,[M3030J:CallDropsonTCH(UplinkandDownlinkQuality)]
,[M3030K:CallDropsonTCH(Other)]
,[CM331:CallDropsonRadioInterfaceinHandoverState(TrafficChannel)]
,[CM332:CallDropsDuetoNoMRfromMSforaLongTime(TrafficChannel)]
,[CM333:CallDropsduetoAbisTerrestrialLinkFailure(TrafficChannel)]
,[CM334:CallDropsduetoEquipmentFailure(TrafficChannel)]
,[CM335:CallDropsduetoForcedHandover(TrafficChannel)]
,[CM337:CallDropsafterAnswer]
,[CM338:SuccessfulConnections]
,[CM339:ClearRequestsSentontheAinterface(TCH)(TrafficChannel)]
,[M3020A:CallDropsonSDCCH(TA)]
,[M3020B:CallDropsonSDCCH(ReceivedLevel)]
,[M3020C:CallDropsonSDCCH(Quality)]
,[M3020D:CallDropsonSDCCH(Other)]
FROM [myDB].[dbo].[mnm_rotterdam_5_daily_details-20191216081027]
Кто-нибудь есть идеи об этой ошибке?