Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
unicode query strings? (sqlalchemy 0.5.0beta1, pyodbc, mssql)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jeremiah  
View profile  
 More options Jul 11 2008, 5:59 pm
From: Jeremiah <jeremiah.campb...@gmail.com>
Date: Fri, 11 Jul 2008 14:59:54 -0700 (PDT)
Local: Fri, Jul 11 2008 5:59 pm
Subject: unicode query strings? (sqlalchemy 0.5.0beta1, pyodbc, mssql)

Hello.  I am having a little problem getting sqlalchemy working.  I am
running mac os x 10.5, sqlalchemy 0.5beta1, pyodbc, mssql 2005.  i
have a simple insert example like below.  This runs with no errors but
inserts no data.  If I try to autload a table's data it gives me the
following error: "No results. Previous SQL was not a query."

        import sqlalchemy as sa

        engine = sa.create_engine(connect-string, echo=True)

        #a meta data object defined elsewhere
        c.metadata.bind = engine

        sa_q = c.dimAsset.insert()
        print sa_q
        sa_q.execute(ColumName = 'Some Value')

I watched these connections via SQL Server Profiler.  I compared the
the above script against the same query when run through pyodbc.

via sql alchemy
---------------------------
declare @p1 int
set @p1=13808
exec sp_prepare @p1 output,NULL,N'',1
select @p1

via pyodbc
-----------------------
declare @p1 int
set @p1=1
exec sp_prepare @p1 output,N'@P1 VARCHAR(11)',N'insert into
schemax.tableName (ColumnName) values(@P1)',1
select @p1

The actual string defining the query is lost with sql alchemy.  I can
get similar results with pyodbc (without using parameters) by passing
a unicode version of the query string.  All queries passed by sql
alchemy show up as empty strings according to the profiler.  I assume
that there is some character formatting mismatch somewhere that causes
this but I am at a loss to say where: sql alchemy, pyodbc, odbc driver
(Actual Technologies), the db server itself.

Any ideas/solutions would be much appreciated.

Thanks.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rick Morrison  
View profile  
 More options Jul 12 2008, 12:48 pm
From: "Rick Morrison" <rickmorri...@gmail.com>
Date: Sat, 12 Jul 2008 12:48:54 -0400
Local: Sat, Jul 12 2008 12:48 pm
Subject: Re: unicode query strings? (sqlalchemy 0.5.0beta1, pyodbc, mssql)

Prima facie, I have no idea why this should be acting this way. You listed
the SQL as seen through profiler, what did you get for statement echos from
the "echo=True" on your engine -- does the query appear there?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Bayer  
View profile  
 More options Jul 12 2008, 10:12 pm
From: Michael Bayer <zzz...@gmail.com>
Date: Sat, 12 Jul 2008 22:12:43 -0400
Local: Sat, Jul 12 2008 10:12 pm
Subject: Re: unicode query strings? (sqlalchemy 0.5.0beta1, pyodbc, mssql)

On Jul 11, 2008, at 5:59 PM, Jeremiah wrote:

> The actual string defining the query is lost with sql alchemy.  I can
> get similar results with pyodbc (without using parameters) by passing
> a unicode version of the query string.  All queries passed by sql
> alchemy show up as empty strings according to the profiler.  I assume
> that there is some character formatting mismatch somewhere that causes
> this but I am at a loss to say where: sql alchemy, pyodbc, odbc driver
> (Actual Technologies), the db server itself.

any kind of encoding issue would raise an error immediately.  You need  
to do some more experimentation, and or produce a more complete test  
case illustrating the behavior you're seeing for us to have any  
further insight.  Experiments include:  what happens if you execute a  
plain string with the engine , i.e. engine.execute("insert into table  
values (:foo)", foo='bar') ?  try it with unicode bind params ?  what  
happens if you execute against a sqlite database instead of MSSQL?  
what happens if you purposefully use a nonexistint column name with  
the insert().execute() parameters ?  are you squashing errors within a  
try/except ?  etc.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremiah  
View profile  
 More options Jul 13 2008, 7:05 pm
From: Jeremiah <jeremiah.campb...@gmail.com>
Date: Sun, 13 Jul 2008 16:05:59 -0700 (PDT)
Local: Sun, Jul 13 2008 7:05 pm
Subject: Re: unicode query strings? (sqlalchemy 0.5.0beta1, pyodbc, mssql)

> Prima facie, I have no idea why this should be acting this way. You listed
> the SQL as seen through profiler, what did you get for statement echos from
> the "echo=True" on your engine -- does the query appear there?

Yes, the query does appear there when echoed.  I can take this query
and paste it into a sql management studio and it runs fine.  I can
also take the generated query and use pyodbc to execute the query.  In
addition I just tested running the generated query using the sql
alchemy engine.execute() method and it runs fine.

> any kind of encoding issue would raise an error immediately.  You need  
> to do some more experimentation, and or produce a more complete test  
> case illustrating the behavior you're seeing for us to have any  
> further insight.  Experiments include:  what happens if you execute a  
> plain string with the engine , i.e. engine.execute("insert into table  
> values (:foo)", foo='bar') ?  try it with unicode bind params ?  what  

at your suggestion I tried executing this with the builtin
engine.execute() method and it seems to work fine.  That surprises me.

the table I have defined is just a test table with one String()
column.  I am not trying to use any unicode bind params.  It just
seems to me that since the query string is what gets lost or mangled
it is some type of character encoding mismatch but I submit I know
very little about unicode.  Nevertheless I will test unicode params
tomorrow and post results.

> happens if you execute against a sqlite database instead of MSSQL?  

i will do further testing against sqlite tomorrow but an initial test
a few days ago let me run the create_all() method.  It did throw an
error when I tried to specify a schema, something like database not
found.  I will post more when I have it.

> what happens if you purposefully use a nonexistent column name with  
> the insert().execute() parameters ?  are you squashing errors within a  

Using a nonexistent column name curiously produces no errors and
runs.  The output (when echo=True for the engine) and the trace are a
bit different though.  It produces a query that specifies no columns
or parameters.  The profiler just shows a series of commits /  empty
strings / roll backs being processed.

> try/except ?  etc.

not currently squashing any errors inside a try/except

Thanks for the assistance and time.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Bayer  
View profile  
 More options Jul 13 2008, 8:24 pm
From: Michael Bayer <zzz...@gmail.com>
Date: Sun, 13 Jul 2008 20:24:59 -0400
Local: Sun, Jul 13 2008 8:24 pm
Subject: Re: unicode query strings? (sqlalchemy 0.5.0beta1, pyodbc, mssql)

On Jul 13, 2008, at 7:05 PM, Jeremiah wrote:

> Using a nonexistent column name curiously produces no errors and
> runs.  The output (when echo=True for the engine) and the trace are a
> bit different though.  It produces a query that specifies no columns
> or parameters.  The profiler just shows a series of commits /  empty
> strings / roll backs being processed.

ok, that one aspect here might be SQLA's fault, in that it's ignoring  
the nonexistent column name instead of raising an error.

I think at this point you should try some pdb stepping just to isolate  
exactly where things are getting lost.   I'm pretty sure you either  
have something weird going on with your DBAPI driver or you're somehow  
using the insert() construct incorrectly (though your sample code  
looked fine).  this is not an issue we've seen before.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google