Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #16493 > unrolled thread

RE: Py and SQL

Started by"Sells, Fred" <fred.sells@adventistcare.org>
First post2011-12-01 06:51 -0500
Last post2011-12-01 06:51 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  RE: Py and SQL "Sells, Fred" <fred.sells@adventistcare.org> - 2011-12-01 06:51 -0500

#16493 — RE: Py and SQL

From"Sells, Fred" <fred.sells@adventistcare.org>
Date2011-12-01 06:51 -0500
SubjectRE: Py and SQL
Message-ID<mailman.3196.1322740280.27778.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

I find it easier to code like this

 

Sql = ‘’’select yadda, yadda, yadda

FROM a,b,c

Where this=that

ORDER BY deudderting’’’

 

With the appropriate %s(varname)  and  % against a dictionary rather than positional args, but that’s just me.

 

From: python-list-bounces+frsells=adventistcare.org@python.org [mailto:python-list-bounces+frsells=adventistcare.org@python.org] On Behalf Of Jerry Hill
Sent: Wednesday, November 30, 2011 5:15 PM
To: Verde Denim
Cc: Python list
Subject: Re: Py and SQL

 

On Wed, Nov 30, 2011 at 3:30 PM, Verde Denim <tdldev@gmail.com> wrote:

dbCursor1.execute('select lpad(' ', 2*level) || c "Privilege, Roles and Users" from ( select null p, name c from system_privilege_map where name like upper(\'%&enter_privliege%\') union select granted_role p, grantee c from dba_role_privs union select privilege p, grantee c from dba_sys_privs) start with p is null connect by p = prior c')


I think this is your problem.  Your string is delimited with single quotes on the outside ('), but you also have a mix of single and double quotes inside your string.  If you were to assign this to a variable and print it out, you would probably see the problem right away. 

You have two options.  First, you could flip the outer quotes to double quotes, then switch all of the quotes inside the string to single quotes (I think that will work fine in SQL).  Second, you could use a triple-quoted string by switching the outer quotes to ''' or """.  Doing that would let you mix whatever kinds of quotes you like inside your string, like this (untested):

sql = '''select lpad(' ', 2*level) || c "Privilege, Roles and Users" from ( select null p, name c from system_privilege_map where name like upper(\'%&enter_privliege%\') union select granted_role p, grantee c from dba_role_privs union select privilege p, grantee c from dba_sys_privs) start with p is null connect by p = prior c'''

dbCursor1.execute(sql)

Once you do that, I think you will find that the "&enter_priviliege" bit in your SQL isn't going to do what you want.  I assume you're expecting that to automatically pop up some sort of dialog box asking the user to enter a value for that variable?  That isn't going to happen in python.  That's a function of the database IDE you use.  You'll need to use python to ask the user for the privilege level, then substitute it into the sql yourself.

-- 
Jerry

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web