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


Groups > comp.lang.python > #16493

RE: Py and SQL

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.chainon-marquant.org!news-transit.tcx.org.uk!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <fred.sells@adventistcare.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'python.': 0.04; 'assign': 0.04; 'string.': 0.04; 'ide': 0.05; 'python': 0.08; "'''": 0.09; 'args,': 0.09; 'positional': 0.09; 'substitute': 0.09; 'wednesday,': 0.15; 'a,b,c': 0.16; 'cc:name:python list': 0.16; 'delimited': 0.16; 'privilege': 0.16; 'sql).': 0.16; 'switching': 0.16; 'cc:addr:python-list': 0.16; 'wed,': 0.17; 'wrote:': 0.18; 'level,': 0.18; 'string,': 0.18; 'to:2**1': 0.21; 'email addr:gmail.com&gt;': 0.21; 'options.': 0.21; 'appropriate': 0.22; 'assume': 0.22; 'header:In-Reply-To:1': 0.22; 'dictionary': 0.23; 'string': 0.24; 'cc:2**0': 0.24; 'fine': 0.24; 'code': 0.25; 'function': 0.27; 'asking': 0.28; 'variable': 0.28; 'bit': 0.28; 'problem': 0.29; 'print': 0.29; 'cc:addr:python.org': 0.29; 'nov': 0.29; 'pm,': 0.29; 'outer': 0.30; 'roles': 0.30; 'second,': 0.30; 'skip:% 10': 0.30; 'cc:': 0.31; 'list': 0.32; "isn't": 0.33; 'sort': 0.33; 'rather': 0.33; 'that,': 0.33; 'probably': 0.34; 'subject:': 0.34; 'skip:& 30': 0.34; 'yourself.': 0.34; 'away.': 0.34; 'mix': 0.34; 'null': 0.34; 'switch': 0.35; 'problem.': 0.36; 'sent:': 0.36; 'skip:p 50': 0.37; 'skip:" 10': 0.37; 'two': 0.37; 'but': 0.37; 'received:192': 0.37; 'think': 0.37; 'could': 0.37; 'skip:& 10': 0.38; 'doing': 0.38; 'received:org': 0.38; 'url:rec- html40': 0.38; 'some': 0.38; 'easier': 0.38; 'from:': 0.39; 'url:org': 0.39; 'url:microsoft': 0.40; 'received:192.168': 0.40; 'once': 0.60; '2011': 0.61; 'your': 0.61; 'double': 0.61; 'happen': 0.61; 'connect': 0.62; 'order': 0.62; 'skip:w 30': 0.63; 'kinds': 0.64; 'hill': 0.68; 'union': 0.72; '30,': 0.74; 'skip:\xe2 10': 0.74; '5:15': 0.84; '8bit%:60': 0.84; 'subject:SQL': 0.84; 'flip': 0.91
X-MimeOLE Produced By Microsoft Exchange V6.5
Content-class urn:content-classes:message
MIME-Version 1.0
Content-Type multipart/alternative; boundary="----_=_NextPart_001_01CCB01F.84C82B55"
Subject RE: Py and SQL
Date Thu, 1 Dec 2011 06:51:10 -0500
In-Reply-To <CADwdpyYU0sHnFKZM-H=4vOxY5UT9gzY2gR5KTBLVZHUwpm1GTA@mail.gmail.com>
X-MS-Has-Attach
X-MS-TNEF-Correlator
Thread-Topic Py and SQL
Thread-Index AcyvrbPZY/UXhBo5S5yovcBbnWXwKwAcYdUQ
References <CAB3cKwzodsPqE-sTh6borkxHccgqdbKMToMrR1CpU4_WdqGmfQ@mail.gmail.com> <CADwdpyYU0sHnFKZM-H=4vOxY5UT9gzY2gR5KTBLVZHUwpm1GTA@mail.gmail.com>
From "Sells, Fred" <fred.sells@adventistcare.org>
To "Jerry Hill" <malaclypse2@gmail.com>, "Verde Denim" <tdldev@gmail.com>
Cc Python list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3196.1322740280.27778.python-list@python.org> (permalink)
Lines 160
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1322740280 news.xs4all.nl 6916 [2001:888:2000:d::a6]:36119
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:16493

Show key headers only | View raw


[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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web