Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQLdb won't insert...SQL works in admin tool

Status
Not open for further replies.

tdrew

IS-IT--Management
Jun 13, 2007
70
US
My SQL statement works fine in my admin tool, but when I run the script I don't get an error but the insert does not go through. Any ideas? I am 2 days old to this.


**********Script**********
#logging.debug("Inserting to DB")
try:
print fullSQL
conn.query(fullSQL)
fileRecordCount+=1
print "done"
except:
logging.critical("Unable to insert the following SQL: " + fullSQL)
logging.error(traceback.print_exc(file=sys.stdout))


...


try:
conn = MySQLdb.connect(host="localhost",user="root",passwd="",db="callmanager")
except:
# Ooops... couldn't connect
logging.critical("Unable to connect to the database. Terminating..")
logging.error(traceback.print_exc(file=sys.stdout))
sys.exit(2)


**********SQL**********
INSERT INTO calldetails (cdrRecordType,globalCallID_callManagerId,globalCallID_callId,origLegCallIdentifier,dateTimeOrigination,origNodeId,origSpan,origIpAddr,callingPartyNumber,callingPartyUnicodeLoginUserID,origCause_location,origCause_value,origPrecedenceLevel,origMediaTransportAddress_IP,origMediaTransportAddress_Port,origMediaCap_payloadCapability,origMediaCap_maxFramesPerPacket,origMediaCap_g723BitRate,origVideoCap_Codec,origVideoCap_Bandwidth,origVideoCap_Resolution,origVideoTransportAddress_IP,origVideoTransportAddress_Port,destLegIdentifier,destNodeId,destSpan,destIpAddr,originalCalledPartyNumber,finalCalledPartyNumber,finalCalledPartyUnicodeLoginUserID,destCause_location,destCause_value,destPrecedenceLevel,destMediaTransportAddress_IP,destMediaTransportAddress_Port,destMediaCap_payloadCapability,destMediaCap_maxFramesPerPacket,destMediaCap_g723BitRate,destVideoCap_Codec,destVideoCap_Bandwidth,destVideoCap_Resolution,destVideoTransportAddress_IP,destVideoTransportAddress_Port,dateTimeConnect,dateTimeDisconnect,lastRedirectDn,pkid,originalCalledPartyNumberPartition,callingPartyNumberPartition,finalCalledPartyNumberPartition,lastRedirectDnPartition,duration,origDeviceName,destDeviceName,origCallTerminationOnBehalfOf,destCallTerminationOnBehalfOf,origCalledPartyRedirectOnBehalfOf,lastRedirectRedirectOnBehalfOf,origCalledPartyRedirectReason,lastRedirectRedirectReason,destConversationId,globalCallId_ClusterID,joinOnBehalfOf,comment,authCodeDescription,authorizationLevel,clientMatterCode,callSecuredStatus,origConversationId) VALUES (1,2,2248012,47589994,1270098024,2,23,-1760880212,'8174262476','\ ',0,0,4,-1760111212,17428,4,20,0,0,0,0,0,0,47111995,2,0,-1911809782,'24715','24715','\ ',0,16,4,-1911111782,17664,4,20,0,0,0,0,0,0,1270098030,1270098050,'24715','a47c3258-a8d5-4f3c-be42-10060d0728f1','P_MPPC_GU','','P_MPPC_GU','P_MPPC_GU',20,'S0/SU0/DS1-0@mppc.vgw03','SEP0021112495DC',0,12,0,0,0,0,0,'StandAloneCluster',0,'','',0,'',0,0
);
 
Nevermind...changed it to this format...

import MySQLdb

# Open database connection
db = MySQLdb.connect("localhost","testuser","test123","TESTDB" )

# prepare a cursor object using cursor() method
cursor = db.cursor()

# Prepare SQL query to INSERT a record into the database.
sql = "INSERT INTO EMPLOYEE(FIRST_NAME, \
LAST_NAME, AGE, SEX, INCOME) \
VALUES ('%s', '%s', '%d', '%c', '%d' )" % \
('Mac', 'Mohan', 20, 'M', 2000)
try:
# Execute the SQL command
cursor.execute(sql)
# Commit your changes in the database
db.commit()
except:
# Rollback in case there is any error
db.rollback()

# disconnect from server
db.close()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top