Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70754
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <larry.martell@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.074 |
| X-Spam-Evidence | '*H*': 0.85; '*S*': 0.00; 'string': 0.09; 'subject:string': 0.09; 'cc:addr:python-list': 0.11; "'foobar'": 0.16; 'different,': 0.16; 'extraneous': 0.16; 'fails.': 0.16; 'finney': 0.16; 'mapping,': 0.16; 'skip:" 70': 0.16; 'wrote:': 0.18; 'looked': 0.18; '>>>': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'example.': 0.24; 'specify': 0.24; 'string,': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'skip:p 30': 0.29; 'message- id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; "skip:' 10": 0.31; 'keys': 0.31; 'larry': 0.31; 'occurs': 0.31; 'post.': 0.31; 'quotes': 0.31; 'writes:': 0.31; 'url:python': 0.33; 'problem': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'building': 0.35; 'there': 0.35; 'marks': 0.36; 'skip:" 50': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'ben': 0.38; 'pm,': 0.38; 'does': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'remove': 0.60; 'url:3': 0.61; 'first': 0.61; 'show': 0.63; 'more': 0.64; 'skip:\xe2 10': 0.65; '8bit%:40': 0.68; 'improvements': 0.68; 'construction': 0.72; "'foo'": 0.84; 'fragments': 0.84; 'url:reference': 0.84; 'not:': 0.91; 'quotation': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=u0dJNSPcEqIBXCZ2TzpGpCUgacRTlf/IPqpHScLKPzM=; b=BFVvGt6+cnS+eJTw00cpwxfHqueXbTZRhvLMzObAXK+Qv+Anit+7v3wXM4Uqc93xf6 My16jqQphHGlPbOUjfcA/VCYWU31GNyPoKi5yYdW2vDD0scXpNk0Mnb4+HEo32VheqPn rxEUQwpbZ5vX5Jgq7CFK+QEpzQ1qy+AhF3LDJjtycj9u92Ykk7VeeoCwnENbRdkTmXJG vpN6kWrWlzoxfOoec7t6J5uPebqo5yjzk/q7uGZtEyfKFBU2MuIWVfPAAeYNbg8z3H8O lqMq2g9GiVocyOvcK3zR++ykySP0u8S13g8brMH1nkdaKeLeckymDpdaZNfl7dhfiQLr E54A== |
| MIME-Version | 1.0 |
| X-Received | by 10.180.89.1 with SMTP id bk1mr915191wib.35.1398821151056; Tue, 29 Apr 2014 18:25:51 -0700 (PDT) |
| In-Reply-To | <85wqe7ipoj.fsf@benfinney.id.au> |
| References | <CACwCsY5VpHrO7-gpk88p+zPyX5VsVcZnv3q1u00F3DPJviaR3Q@mail.gmail.com> <85wqe7ipoj.fsf@benfinney.id.au> |
| Date | Tue, 29 Apr 2014 19:25:51 -0600 |
| Subject | Re: pyodbc connect string |
| From | Larry Martell <larry.martell@gmail.com> |
| To | Ben Finney <ben@benfinney.id.au> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | "python-list@python.org" <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9601.1398821153.18130.python-list@python.org> (permalink) |
| Lines | 72 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1398821153 news.xs4all.nl 2839 [2001:888:2000:d::a6]:33856 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:70754 |
Show key headers only | View raw
On Tue, Apr 29, 2014 at 7:14 PM, Ben Finney <ben@benfinney.id.au> wrote:
> Larry Martell <larry.martell@gmail.com> writes:
>
>> I am having a problem building a connect string for pyodbc. It works
>> when everything is hard coded, but if I build the connect string it
>> fails.
>>
>> This works:
>>
>> pyodbc.connect('DRIVER=FreeTDS;' 'SERVER=xx.xx.xx.xx;' 'PORT=1433;'
>> 'DATABASE=blah;' 'UID=foo;' 'PWD=bar;')
>
> This calls the function with a single string,
> "DRIVER=FreeTDS;SERVER=xx.xx.xx.xx;PORT=1433;DATABASE=blah;UID=foo;PWD=bar;".
>
> Remember that consecutive, whitespace-separated, quote-delimited
> fragments specify the construction of a single string literal::
>
> >>> 'foo'
> 'foo'
> >>> 'foo' 'bar'
> 'foobar'
> >>> 'foo' 'bar' 'baz'
> 'foobarbaz'
>
> See the reference for how this concatenation occurs
> <URL:https://docs.python.org/3/reference/lexical_analysis.html#string-literal-concatenation>.
>
>> But this does not:
>>
>> pyodbc.connect(conn_str)
>>
>> Where conn_str is:
>>
>> 'DRIVER=FreeTDS;' 'SERVER=xx.xx.xx.xx;' 'PORT=1433;' 'DATABASE=blah;'
>> 'UID=foo;' 'PWD=bar;'
>
> This string is different, because it contains a whole lot of quotation
> marks and whitespace not in the string you show in the first example.
>
>> conn_str is constructed with:
>>
>> conn_str = "'DRIVER=%s;' 'SERVER=%s;' 'PORT=%s;' 'DATABASE=%s;'
>> 'UID=%s;' 'PWD=%s;'" \
>> % (RECIPE_DB['DRIVER'], RECIPE_DB['SERVER'],
>> RECIPE_DB['PORT'], RECIPE_DB['DATABASE'],
>> RECIPE_DB['USER'], RECIPE_DB['PASSWORD'])
>
> Remove the extraneous quotes and whitespace, which were not in the
> original string you showed above.
>
> On a separate point: Since you have string keys for the mapping, you can
> make the interpolation more readable::
>
> conn_str = (
> "DRIVER=%(DRIVER)s;SERVER=%(SERVER)s;PORT=%(PORT)s;"
> "DATABASE=%(DATABASE)s;UID=%(USER)s;PWD=%(PASSWORD)s;"
> ) % RECIPE_DB
>
> since the named placeholders will be looked up by key in the ‘RECIPE_DB’
> mapping.
>
> There are other improvements to suggest, but I don't want to distract
> from the main point of the post.
Thanks for the explanation.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: pyodbc connect string Larry Martell <larry.martell@gmail.com> - 2014-04-29 19:25 -0600
csiph-web