[Tutor] Searching for email id in MySQL giving wrong results [ Try out pattern Search ]
John Joseph
jjk_saji at yahoo.com
Mon Jan 23 12:41:57 CET 2006
Hi
Thanks for the tip
now I am trying to do pattern matching for MySQL , but
I am not getting the result
on MySQL , to select for all email starting with
jos we do
select * from contact where email_id like "jos%";
but I get confused how to use it , while executing
it in python , how to call the pattern matching inside
mysql query
I had added my code
Thanks
Joseph John
***********************************************************
import MySQLdb
s_email= raw_input("Enter the some part of the Email
to be searched ")
db = MySQLdb.connect(host="localhost",user = "john",
passwd = "asdlkj", db = 'learnpython')
entry = db.cursor()
#entry.execute('''SELECT * FROM contact WHERE email_id
like %s''', (s_email,))
#s = entry.fetchall()
#print s
entry.execute('''SELECT * FROM contact WHERE email_id
like %s''', (s_email,))
s = entry.fetchall()
print s
~
~
--- "ZIYAD A. M. AL-BATLY" <zamb at saudi.net.sa> wrote:
> On Sun, 2006-01-22 at 12:43 +0000, John Joseph
> wrote:
> > Hi
> Hi John...
>
> Most of your problems in your code seems to be
> caused by a single
> mistake. Compare the following two strings and you
> should figure out
> what's wrong by yourself:
>
> email_id = 'email at domain.tld'
>
> wrong_string = '''SELECT s FROM t WHERE
> id=%s''' , (email_id)
> right_string = '''SELECT s FROM t WHERE
> id=%s''' % (email_id)
>
> print "Wrong:", wrong_string
> print "Right:", right_string
>
> This is the output:
> Wrong: ('SELECT s FROM t WHERE id=%s',
> 'email at domain.tld')
> Right: SELECT s FROM t WHERE
> id=email at domain.tld
>
> Now, which one is the right one? And which one is
> the one you want?
>
>
> I suggest you study strings more, especially
> concatenation and '%'.
>
> If you need more help, just post to the mailing list
> again.
> Ziyad.
>
>
___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com
More information about the Tutor
mailing list