944,004 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 2727
  • Python RSS
Sep 29th, 2005
0

Function calling- numeric or char

Expand Post »
I built a function as following
Python Syntax (Toggle Plain Text)
  1. def IsExists(fxfcustid):
  2.  
  3. #global noduplicates
  4.  
  5. db = db_connect("triumph","freight","vcpdb")
  6. cursor = db2.cursor()
  7.  
  8. #*************************************************************************
  9. #*** Query to get entries made by the person acessing the system ***
  10. #*************************************************************************
  11.  
  12. sql = '''select count(*)
  13. from triumph.fxf_salescontest_entry
  14. where fxf_acct_nbr = %(fxfcustid)s)
  15. and (delete_flag is null or
  16. delete_flag not in ('Y','y')) ''' % vars()
  17. try:
  18. cursor.execute( sql )
  19. noduplicates = cursor2.fetchall();
  20. except:
  21. noduplicates = [('None')]
  22.  
  23. cursor.close()
  24. db.close()
  25. return
  26.  
  27. ### later on, it was called by followiging code:
  28. isExists(fxfcustid)
  29. if noduplicates != 0:
  30. print mainscreen(empno,'This customer has been entered. Request failed',0,'')
  31. else:
  32. cursor.execute(insertSql % vars())

But it doesn't work. what's wrong with this code? is noduplicates number or string? any help is highly appreciated.

Thanks,

Jackie

Edit: code tags added by vegaseat
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jchang is offline Offline
2 posts
since Sep 2005
Oct 8th, 2005
0

Re: Function calling- numeric or char

Well jchang, I am not exacly sure where the problem is ,but can u check on the following syntax in your code... Hope it helps

In the main code where u call this function

isExists(fxfcustid) is actually supposed to be "IsExists(fxfcustid)"
functions are case sensitive...But if you are not facing a problem here, maybe the next one could be bothering...

I have never used three ' ' ' ( and I have no idea how it works)
In your code

sql = '''select count(*)
from triumph.fxf_salescontest_entry
where fxf_acct_nbr = %(fxfcustid)s)
and (delete_flag is null or
delete_flag not in ('Y','y')) ''' % vars()



Here 'fxcustid' seems to be caught within the string, I mean it has become a part of the string... why dont u try

sql = "select count(*) from triumph.fxf_salescontest_entry where fxf_acct_nbr = %(" + fxfcustid + ")s) and (delete_flag is null or delete_flag not in ('Y','y'))" % vars()

I have very little knowledge in SQL Queries, I dont know whether the above syntax is right, hope it helps you in some way...
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
xav.vijay is offline Offline
52 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Segmentation fault
Next Thread in Python Forum Timeline: Merging Dictionary





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC