Ich mache ein Python-Skript mit pyodbc, so jetzt habe ich diese Schwierigkeiten, das Skript bekommt einige Daten aus einer Tabelle, eine dieser Daten ist ein Smaillint-Typ und seine zu sein eine Zeit, so legen sie dieses Skript in einer anderen Tabelle diese Informationen aber wenn es diesem Feld seine falsch ein:Einfügen von smallint zu einer Zeit pyodbc
Etwas wie:
Select date (SMALLINT):
By the way, ich verwende nur Intervalle 30 min:
0
30
130
200
230
1530
1600
Und wenn sein sein zu einer Zeit, Typ-Tabelle eingefügt:
00:00:00
00:00:30
00:01:30
00:02:00
00:02:30
00:15:30
00:16:00
Und seine suppouse
00:00:00
00:30:00
01:30:00
02:00:00
02:30:00
15:30:00
16:00:00
Dies ist mein Code zu sein:
# ------------------------------------
# Creando Registro de Inicio ****hagent****
# ------------------------------------
finicio = datetime.datetime.now()
valores = (finicio_script, fichero, finicio, ip, ipDestino[cont], tablas[0])
#print valores #Prueba de valores a insertar
#Se comienza con la creacion de registro en BDD local
print "Realizando creacion de Log de Registro"
cadenaSQL = (
"INSERT INTO log_scripts_CMS(id_proceso, fichero, fecha_hora_inicio, srv_origen, "
"srv_destino, tipo_script) VALUES (?, ?, ?, ?, ?, ?)"
)
#print cadenaSQL #Prueba de query
registro_cursor.execute(cadenaSQL, valores)
#Se empieza con la insercion de datos a las bdd
print "Insertando datos a", ipDestino[cont]+ " tabla: " + tablas [0]
cadenaSQL = (
"INSERT IGNORE INTO "+tablas[0]+"(row_date, **starttime_utc**, intrvl, acd, skill, extension, "
"logid, loc_id, rsv_level, i_stafftime, ti_stafftime, i_availtime, ti_availtime, i_acdtime, i_acwtime, "
"i_acwouttime, i_acwintime, ti_auxtime, i_auxouttime, i_auxintime, i_othertime, acwincalls, acwintime, "
"auxincalls, auxintime, acwoutcalls, acwouttime, acwoutoffcalls, acwoutofftime, acwoutadjcalls, "
"auxoutcalls, auxouttime, auxoutoffcalls, auxoutofftime, auxoutadjcalls, event1, event2, event3, "
"event4, event5, event6, event7, event8, event9, assists, acdcalls, acdtime, acwtime, o_acdcalls, "
"o_acdtime, o_acwtime, da_acdcalls, da_anstime, da_abncalls, da_abntime, holdcalls, holdtime, holdabncalls, "
"transferred, conference, abncalls, abntime, i_ringtime, i_da_acdtime, i_da_acwtime, da_acdtime, da_acwtime, "
"da_othercalls, da_othertime, ringcalls, ringtime, ansringtime, ti_othertime, da_acwincalls, da_acwintime, "
"da_acwocalls, da_acwotime, da_acwoadjcalls, da_acwooffcalls, da_acwoofftime, noansredir, incomplete, "
"acdauxoutcalls, i_acdaux_outtime, i_acdauxintime, i_acdothertime, phantomabns, i_auxtime, holdacdtime, "
"da_release, acd_release, ti_auxtime0, ti_auxtime1, ti_auxtime2, ti_auxtime3, ti_auxtime4, ti_auxtime5, "
"ti_auxtime6, ti_auxtime7, ti_auxtime8, ti_auxtime9, acdcalls_r1, acdcalls_r2, i_otherstbytime, i_auxstbytime"
") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?"
",?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,"
"?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"
)
#print (cadenaSQL) #Comprobaacion de query
#Se insertan datos en bdd local
if cuenta_hagent != 0:
crsr.executemany(cadenaSQL, hagent)
print "Listo!"
else:
print "No hay datos por insertar"
EDIT:
Das, wie ich das dat bekam eine aus einer anderen Tabelle sie in einer anderen Datenbank zu speichern:
# ------------------------------------
# Obtencion de datos de la tabla hagent
# ------------------------------------
tablas_informix = ["hagent", "hsplit", "intradaytramo", "loginout"]
#Se obtienen los datos.
print "Recuperando datos de la tabla ", tablas_informix[0]
#Se obtienen datos de la tabla hagent
cadenaSQL = (
"SELECT hagent.row_date AS FECHA, hagent.starttime AS starttime, hagent.intrvl AS intrvl, hagent.acd AS acd, hagent.split AS skill, "
"hagent.extension, hagent.logid, hagent.loc_id, hagent.rsv_level, hagent.i_stafftime, hagent.ti_stafftime, hagent.i_availtime, "
"hagent.ti_availtime, hagent.i_acdtime, hagent.i_acwtime, hagent.i_acwouttime, hagent.i_acwintime, hagent.ti_auxtime, hagent.i_auxouttime, "
"hagent.i_auxintime, hagent.i_othertime, hagent.acwincalls, hagent.acwintime, hagent.auxincalls, hagent.auxintime, hagent.acwoutcalls, "
"hagent.acwouttime, hagent.acwoutoffcalls, hagent.acwoutofftime, hagent.acwoutadjcalls, hagent.auxoutcalls, hagent.auxouttime, "
"hagent.auxoutoffcalls, hagent.auxoutofftime, hagent.auxoutadjcalls, hagent.event1, hagent.event2, hagent.event3, hagent.event4, "
"hagent.event5, hagent.event6, hagent.event7, hagent.event8, hagent.event9, hagent.assists, hagent.acdcalls, hagent.acdtime, "
"hagent.acwtime, hagent.o_acdcalls, hagent.o_acdtime, hagent.o_acwtime, hagent.da_acdcalls, hagent.da_anstime, hagent.da_abncalls, "
"hagent.da_abntime, hagent.holdcalls, hagent.holdtime, hagent.holdabncalls, hagent.transferred, hagent.conference, hagent.abncalls, "
"hagent.abntime, hagent.i_ringtime, hagent.i_da_acdtime, hagent.i_da_acwtime, hagent.da_acdtime, hagent.da_acwtime, hagent.da_othercalls, "
"hagent.da_othertime, hagent.ringcalls, hagent.ringtime, hagent.ansringtime, hagent.ti_othertime, hagent.da_acwincalls, hagent.da_acwintime, "
"hagent.da_acwocalls, hagent.da_acwotime, hagent.da_acwoadjcalls, hagent.da_acwooffcalls, hagent.da_acwoofftime, hagent.noansredir, "
"hagent.incomplete, hagent.acdauxoutcalls, hagent.i_acdaux_outtime, hagent.i_acdauxintime, hagent.i_acdothertime, hagent.phantomabns, "
"hagent.i_auxtime, hagent.holdacdtime, hagent.da_release, hagent.acd_release, hagent.ti_auxtime0, hagent.ti_auxtime1, hagent.ti_auxtime2, "
"hagent.ti_auxtime3, hagent.ti_auxtime4, hagent.ti_auxtime5, hagent.ti_auxtime6, hagent.ti_auxtime7, hagent.ti_auxtime8, hagent.ti_auxtime9, "
"hagent.acdcalls_r1, hagent.acdcalls_r2, hagent.i_otherstbytime, hagent.i_auxstbytime FROM root.hagent "
"WHERE(hagent.row_date = '"+fecha_consulta+"') AND hagent.acd = '"+str(acd[0])+"' AND hagent.split IN ("+condicionIn+") AND starttime = "+hora_query+" "
"ORDER BY starttime;"
)
#Se inicializa cursor.
cursor = cnxn.cursor()
cursor.execute(cadenaSQL)
hagent = []
hagent = cursor.fetchall()
print "Listo!"
#print cadenaSQL
cnxn.commit()
Bitte [Bearbeiten] Ihre Frage die Zuordnung von SMALLINT besser erklären zu ZEIT. Zum Beispiel, wenn "130" entspricht "13: 00: 00" dann was entspricht "131"? –
Übrigens, wenn ich pyodbc verwende, um den Integer-Wert '130' in eine 'TIME'-Spalte einzufügen, bekomme ich' 00: 01: 30', nicht '00: 13: 00'. –
Überprüfen Sie Ihre Arbeit. Die von Ihnen angezeigten Beispielergebnisse sind inkonsistent. Wenn '200'' 00: 02: 00' erzeugt und '230'' 00: 02: 30' erzeugt, dann würde ich erwarten, dass '130'' 00: 01: 30' (wie ich es bekomme), nicht '00: 13: 00'. –