[sqlalchemy] MySQL tx_isolation fixed in 1.1 but not in 1.2

2017-12-01 Thread Josh Anyan




cursor.execute('SELECT @@tx_isolation') generates a warning with MySQL 5.7+ 


That warning has been fixed in 1.1. But there seems to be a regression with 1.2 
in that the fix is no longer present.


dialects/mysql/base.py?rel_1_2_0b2 

 vs dialects/mysql/base.py?rel_1_1 


The relevant commit 

 
can likely be applied to the 1.2 branch as well. 

Would you like a pull request for this or would it be easier to grab the 
commit and apply it yourself?

--
Josh A.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Writing a Table that changes its schema and name if ii's used with PostgreSQL or Oracle

2017-12-01 Thread Mike Bayer
On Thu, Nov 30, 2017 at 4:24 PM, Massimiliano della Rovere
 wrote:
> Greetings,
> I'm writing to ask some hints for my problem.
>
> I am using SQLAlchemy Core (no ORM, because everything it is wrapped by
> sqlachemy_aio - everything happens inside a asyncio loop).
>
> The program I'm working on can be deployed with a PostgreSQL or an Oracle
> DB, customer choice, I have no power on this.
> My problem is writing Table(s) definitions whose name and schema change
> depending on the DB that will be used.
> If the table name is "table" and the schema name is "schema" (I mean the
> schema= parameter of sqlalchemy.schema.Table):
> * with PostgreSQL, the table name should be "table" and the schema "schema".
> * with Oracle, the table name should be "schema_table" and there should be
> no schema (the default one for the user logging onto Oracle).
>
> With PostgreSQL, the program uses multiple table grouped in different
> schemas, so different Table instances will be grouped in different schema,
> and there will be inter-schema Foreign Keys.
> Also the solution should be compatible with Alembic, as it is used for
> versioning.
> When the program is deployed, a file contains the information whether the DB
> in use is PostgreSQL or Oracle.
>
> One idea (but I think it won't work with Alembic), is to create a new class
> that inherits from sqlalchemy.schema.Table and overrides the __new__ method:
>
> # python3code
> class CustomTable(Table):
> def __new__(cls, *args, **kw):
> database_type = read_database_type()
> if database_type == "oracle":
> try:
> schema = kw.pop("schema")
> except KeyError:
> pass
> else:
> tablename = f"{schema}_{args[0]}"
> return super().__new__(cls, tablename, *args[1:], **kw)
> return super().__new__(cls, *args, **kw)
>
> It would be nice to create a similar class for Alembic, to customize the
> op.create_table and op.drop_table statement.
> Before writing further code, I'd like to ask whether there are built in
> mechanisms in sqlalchemy to address this problem.

I would use string rewriting at the SQL execution level. Use a
easily-identifiable naming scheme for your schemas and tables such
that you can regular expression at the statement level.   like
"__SCHEMA_schemaname" and "__TABLE_tablename", or maybe something less
jarring than that.   Then for Oracle you need to regexp for
"__SCHEMA_schemaname\.__TABLE_tablename" and replace with your value,
and on Postgresql you need to just filter out "__SCHEMA_" and
"__TABLE_".  The event you'd use is before_cursor_execute:
http://docs.sqlalchemy.org/en/latest/core/events.html?highlight=before_cursor_execute#sqlalchemy.events.ConnectionEvents.before_cursor_execute
using the second form, which includes retval=True.






>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> 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 https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Re: Influencing what CREATE statement generated in sqlalchemy

2017-12-01 Thread su-sa
Thanks a lot Mike!

On Thursday, 30 November 2017 11:32:05 UTC+1, su-sa wrote:
>
> Hi everyone,
>
> does someone maybe know if one can from the dialect somehow influence what 
> CREATE TABLE statement would be generated in certain cases? 
>
> So for example: In the tests for temporary table I saw that for Oracle, 
> the create table statement has been adjusted, but that only ís a hack to 
> make the tests pass and what if someone really wants to create a temporary 
> table using oracle(for ex. CREATE GLOBAL TEMPORARY TABLE) and 
> sqlalchemy?  As far as I understood, one cannot in the sqlalchemy framework 
> influence the CREATE TABLE statement, or am I wrong?
>
> Another question, is there also a way in sqlalchemy to specify if one 
> wants to make a column table or row table? Couldn't really find something 
> similar.
>
> Thanks in advance,
> S
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Re: Tracking new relationships

2017-12-01 Thread Tolstov Sergey
Solved, SQlalchemy create object based on instance, i didn't guess that, 
sorry

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.