Re: [sqlalchemy] SQLAlchemy as plain-SQL generator

2015-04-22 Thread Jonathan Vanasco
Just be warned of this method -- make sure you're using the most recent 
SqlAlchemy version in the .9x or 1.x branches.  Earlier versions would not 
apply LIMIT or OFFSET into the bind.

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] SQLAlchemy as plain-SQL generator

2015-04-22 Thread Pavel S
Hi Mike, your solutions works too. Thanks to you both!


Dne středa 22. dubna 2015 16:07:28 UTC+2 Michael Bayer napsal(a):
>
>  
>
> On 4/22/15 8:27 AM, Richard Gerd Kuesters wrote:
>  
> hi,
>
> you must use a specific dialect so sqlalchemy can create it for you. not 
> the best usage, imho, but here it goes:
>
> *stmt = query.compile().process(query, literal_binds=True)*
>
>
> OK since Pavel noted the double compile, if you want the literal_binds 
> part (not clear if that is needed here?), it goes into compile()
>
> stmt = str(query.compile(compile_kwargs={"literal_binds": True}))
>
>
>
>
>
>  
> i don't know if you want it formated or what, if so, *sqlparse* provides 
> a good way to do it.
>
> but, again, this will only work if you BIND an engine to your metadata, so 
> sqlalchemy can write the right sql for you. also, your query should be a 
> *select()* object, like your example.
>
> this worked for me for some time, using SA 0.9, i don't know about 1.0, 
> but it should work too.
>
>
> cheers,
> richard.
>
>
> On 04/22/2015 04:26 AM, Pavel S wrote:
>  
> Hello,
>
> I have pythonic application which imports custom module written in C++ 
> using boost::python.
> The module creates database connection(s) and executes queries.
> The python calls various methods on that module and passes plain SQL into 
> them. Results are then returned to python.
>
> I would like to use SQLALchemy Core to generate plain SQL strings which 
> will be passed the module.
>
> Lets say I want to generate the following string:
>
>  SELECT A, B FROM Tbl WHERE C = "Foo";
>  
> The equivalent in SA is:
>
>  query = select([
> Tbl.c.A,
> Tbl.c.B
> ]).where(
> Tbl.c.C == "Foo"
> )
>  
> How can I produce the string from that query?
>  -- 
> 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 sqlalchemy+...@googlegroups.com .
> To post to this group, send email to sqlal...@googlegroups.com 
> .
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>
>
> -- 
> 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 sqlalchemy+...@googlegroups.com .
> To post to this group, send email to sqlal...@googlegroups.com 
> .
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>
>
> 

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] SQLAlchemy as plain-SQL generator

2015-04-22 Thread Richard Gerd Kuesters
yeah, well, that's much simpler. in my scenario, where i had to use this 
piece of code, literal_binds are necessary since the query is somehow 
huge, with lots of alias and parameters :)



On 04/22/2015 11:07 AM, Mike Bayer wrote:



On 4/22/15 8:27 AM, Richard Gerd Kuesters wrote:

hi,

you must use a specific dialect so sqlalchemy can create it for you. 
not the best usage, imho, but here it goes:


*stmt = query.compile().process(query, literal_binds=True)*


OK since Pavel noted the double compile, if you want the literal_binds 
part (not clear if that is needed here?), it goes into compile()


stmt = str(query.compile(compile_kwargs={"literal_binds": True}))







i don't know if you want it formated or what, if so, 
*sqlparse*provides a good way to do it.


but, again, this will only work if you BIND an engine to your 
metadata, so sqlalchemy can write the right sql for you. also, your 
query should be a *select()*object, like your example.


this worked for me for some time, using SA 0.9, i don't know about 
1.0, but it should work too.



cheers,
richard.


On 04/22/2015 04:26 AM, Pavel S wrote:

Hello,

I have pythonic application which imports custom module written in 
C++ using boost::python.

The module creates database connection(s) and executes queries.
The python calls various methods on that module and passes plain SQL 
into them. Results are then returned to python.


I would like to use SQLALchemy Core to generate plain SQL strings 
which will be passed the module.


Lets say I want to generate the following string:

|
SELECT A,B FROM TblWHERE C ="Foo";
|

The equivalent in SA is:

|
query =select([
Tbl.c.A,
Tbl.c.B
]).where(
Tbl.c.C =="Foo"
)
|

How can I produce the string from that query?
--
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 sqlalchemy+unsubscr...@googlegroups.com 
.
To post to this group, send email to sqlalchemy@googlegroups.com 
.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
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 sqlalchemy+unsubscr...@googlegroups.com 
.
To post to this group, send email to sqlalchemy@googlegroups.com 
.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
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 sqlalchemy+unsubscr...@googlegroups.com 
.
To post to this group, send email to sqlalchemy@googlegroups.com 
.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
<>

Re: [sqlalchemy] SQLAlchemy as plain-SQL generator

2015-04-22 Thread Mike Bayer



On 4/22/15 8:27 AM, Richard Gerd Kuesters wrote:

hi,

you must use a specific dialect so sqlalchemy can create it for you. 
not the best usage, imho, but here it goes:


*stmt = query.compile().process(query, literal_binds=True)*


OK since Pavel noted the double compile, if you want the literal_binds 
part (not clear if that is needed here?), it goes into compile()


stmt = str(query.compile(compile_kwargs={"literal_binds": True}))







i don't know if you want it formated or what, if so, 
*sqlparse*provides a good way to do it.


but, again, this will only work if you BIND an engine to your 
metadata, so sqlalchemy can write the right sql for you. also, your 
query should be a *select()*object, like your example.


this worked for me for some time, using SA 0.9, i don't know about 
1.0, but it should work too.



cheers,
richard.


On 04/22/2015 04:26 AM, Pavel S wrote:

Hello,

I have pythonic application which imports custom module written in 
C++ using boost::python.

The module creates database connection(s) and executes queries.
The python calls various methods on that module and passes plain SQL 
into them. Results are then returned to python.


I would like to use SQLALchemy Core to generate plain SQL strings 
which will be passed the module.


Lets say I want to generate the following string:

|
SELECT A,B FROM TblWHERE C ="Foo";
|

The equivalent in SA is:

|
query =select([
Tbl.c.A,
Tbl.c.B
]).where(
Tbl.c.C =="Foo"
)
|

How can I produce the string from that query?
--
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 sqlalchemy+unsubscr...@googlegroups.com 
.
To post to this group, send email to sqlalchemy@googlegroups.com 
.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
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 sqlalchemy+unsubscr...@googlegroups.com 
.
To post to this group, send email to sqlalchemy@googlegroups.com 
.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] SQLAlchemy as plain-SQL generator

2015-04-22 Thread Richard Gerd Kuesters
well, i know that repeating (query) is somehow strange, i believe the 
main reason is that *compile()**.process*are not "bound" to the query 
anymore (*i might be wrong*). well, for me it was a one time solution, 
perhaps a little digging can bring you a better approach :)


cheers,
richard.


On 04/22/2015 09:36 AM, Pavel S wrote:

Hi Richard,

thanks, your solution works. ( I don't need formatted output)

However using /query/ twice in the expression looks to me a bit 
awkward. Isn't there some shortcut?



Dne středa 22. dubna 2015 14:27:41 UTC+2 Richard Kuesters napsal(a):

hi,

you must use a specific dialect so sqlalchemy can create it for
you. not the best usage, imho, but here it goes:

*stmt = query.compile().process(query, literal_binds=True)*

i don't know if you want it formated or what, if so,
*sqlparse*provides a good way to do it.

but, again, this will only work if you BIND an engine to your
metadata, so sqlalchemy can write the right sql for you. also,
your query should be a *select()*object, like your example.

this worked for me for some time, using SA 0.9, i don't know about
1.0, but it should work too.


cheers,
richard.


On 04/22/2015 04:26 AM, Pavel S wrote:

Hello,

I have pythonic application which imports custom module written
in C++ using boost::python.
The module creates database connection(s) and executes queries.
The python calls various methods on that module and passes plain
SQL into them. Results are then returned to python.

I would like to use SQLALchemy Core to generate plain SQL strings
which will be passed the module.

Lets say I want to generate the following string:

|
SELECT A,B FROM TblWHERE C ="Foo";
|

The equivalent in SA is:

|
query =select([
Tbl.c.A,
Tbl.c.B
]).where(
Tbl.c.C =="Foo"
)
|

How can I produce the string from that query?
-- 
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 sqlalchemy+...@googlegroups.com .
To post to this group, send email to sqlal...@googlegroups.com
.
Visit this group at http://groups.google.com/group/sqlalchemy
.
For more options, visit https://groups.google.com/d/optout
.


--
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 sqlalchemy+unsubscr...@googlegroups.com 
.
To post to this group, send email to sqlalchemy@googlegroups.com 
.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
<>

Re: [sqlalchemy] SQLAlchemy as plain-SQL generator

2015-04-22 Thread Pavel S
Hi Richard,

thanks, your solution works. ( I don't need formatted output)

However using *query* twice in the expression looks to me a bit awkward. 
Isn't there some shortcut?


Dne středa 22. dubna 2015 14:27:41 UTC+2 Richard Kuesters napsal(a):
>
>  hi,
>
> you must use a specific dialect so sqlalchemy can create it for you. not 
> the best usage, imho, but here it goes:
>
> *stmt = query.compile().process(query, literal_binds=True)*
>
> i don't know if you want it formated or what, if so, *sqlparse* provides 
> a good way to do it.
>
> but, again, this will only work if you BIND an engine to your metadata, so 
> sqlalchemy can write the right sql for you. also, your query should be a 
> *select()* object, like your example.
>
> this worked for me for some time, using SA 0.9, i don't know about 1.0, 
> but it should work too.
>
>
> cheers,
> richard.
>
>
> On 04/22/2015 04:26 AM, Pavel S wrote:
>  
> Hello,
>
> I have pythonic application which imports custom module written in C++ 
> using boost::python.
> The module creates database connection(s) and executes queries.
> The python calls various methods on that module and passes plain SQL into 
> them. Results are then returned to python.
>
> I would like to use SQLALchemy Core to generate plain SQL strings which 
> will be passed the module.
>
> Lets say I want to generate the following string:
>
>  SELECT A, B FROM Tbl WHERE C = "Foo";
>  
> The equivalent in SA is:
>
>  query = select([
> Tbl.c.A,
> Tbl.c.B
> ]).where(
> Tbl.c.C == "Foo"
> )
>  
> How can I produce the string from that query?
>  -- 
> 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 sqlalchemy+...@googlegroups.com .
> To post to this group, send email to sqlal...@googlegroups.com 
> .
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>
>
> 

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] SQLAlchemy as plain-SQL generator

2015-04-22 Thread Richard Gerd Kuesters

hi,

you must use a specific dialect so sqlalchemy can create it for you. not 
the best usage, imho, but here it goes:


*stmt = query.compile().process(query, literal_binds=True)*

i don't know if you want it formated or what, if so, *sqlparse*provides 
a good way to do it.


but, again, this will only work if you BIND an engine to your metadata, 
so sqlalchemy can write the right sql for you. also, your query should 
be a *select()*object, like your example.


this worked for me for some time, using SA 0.9, i don't know about 1.0, 
but it should work too.



cheers,
richard.


On 04/22/2015 04:26 AM, Pavel S wrote:

Hello,

I have pythonic application which imports custom module written in C++ 
using boost::python.

The module creates database connection(s) and executes queries.
The python calls various methods on that module and passes plain SQL 
into them. Results are then returned to python.


I would like to use SQLALchemy Core to generate plain SQL strings 
which will be passed the module.


Lets say I want to generate the following string:

|
SELECT A,B FROM TblWHERE C ="Foo";
|

The equivalent in SA is:

|
query =select([
Tbl.c.A,
Tbl.c.B
]).where(
Tbl.c.C =="Foo"
)
|

How can I produce the string from that query?
--
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 sqlalchemy+unsubscr...@googlegroups.com 
.
To post to this group, send email to sqlalchemy@googlegroups.com 
.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
<>