The statement is likely being invoked but is in a transaction that isn’t 
getting committed (assuming you’re using commit() with pyodbc).   SQLAlchemy 
has an “autocommit” feature that by default looks for SQL strings that indicate 
a COMMIT should occur.  So in this case you should make sure there’s an 
explicit transaction or explicit autocommit.  In 0.7 you’re probably best off 
like this:

conn = engine.connect()
trans = conn.begin()
conn.execute(“your sql”)
trans.commit()

or use the “autocommit” option:

conn = engine.connect()
conn.execution_options(autocommit=True).execute(“your sql”)



On Jan 9, 2014, at 6:39 PM, Sylvester Steele <[email protected]> wrote:

> Hi,
>  
> I am using SQLAlchemy version 0.7.6 with pyodbc to connect to MSSQL 2012.
> Currently I am using SQLAlchemy only for its connection pooling etc. So, at 
> the moment I only use the engine.execute function to execute string queries.
>  
> Weirdly, the following query seems to have no effect at all:
>  
>           SET NOCOUNT ON;
>           SET ROWCOUNT 10000
>           WHILE 1 = 1
>               BEGIN
>                      DELETE from MyTable where MyDate = '20111130'
>                   IF @@rowcount < 10000
>                       BREAK;
>               END
>           SET ROWCOUNT 0;
>           SET NOCOUNT OFF;
>  
> Running the above query using pyodbc directly, works. But with SQLAlchemy it 
> has no effect. There is no error thrown, just a silent failure to execute.
>  
>  
> I enabled ODBC tracing and I found this:
>  
> python  -c "imp 85bc-7d4c EXIT  SQLDriverConnectW  with return code 1 
> (SQL_SUCCESS_WITH_INFO)
>   HDBC                0x000000000057B770
>   HWND                0x0000000000000000
>   WCHAR *             0x000007FEF8CB8F08 [      -3] "******\ 0"
>   SWORD                       -3 
>   WCHAR *             0x000007FEF8CB8F08 <Invalid buffer length!> [-3]
>   SWORD                       -3 
>   SWORD *             0x0000000000000000
>   UWORD                        0 <SQL_DRIVER_NOPROMPT>
>  
> However, the above was also present when I ran the query through pyodbc only. 
> So, this probably indicates a more general problem with the set up, rather 
> than something particular with SQLAlchemy.
>  
> Any idea what might be causing this?
>  
> Thanks
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to