×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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
);

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

(OP)
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()

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close