Re: [sqlalchemy] Rename attributes in autogenerated class

2019-10-14 Thread Mike Bayer
Hi there -

you might have better luck asking on their tracker at 
https://github.com/agronholm/sqlacodegen in case people on here don't have 
sqlacodegen experience.



On Mon, Oct 14, 2019, at 5:34 PM, Vishani Kankariya wrote:
> Is it possible to rename columns in the classes that sqlacodegen generates 
> from a database?
> 

> --
>  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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/59b74aee-74a2-4066-ad94-3e4451ca5857%40googlegroups.com
>  
> .

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/f1872f0d-f41f-4496-9743-9da42ac59a6f%40www.fastmail.com.


[sqlalchemy] Rename attributes in autogenerated class

2019-10-14 Thread Vishani Kankariya
Is it possible to rename columns in the classes that sqlacodegen generates 
from a database?

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/59b74aee-74a2-4066-ad94-3e4451ca5857%40googlegroups.com.


Re: [sqlalchemy] delete of polymorphic objects leaves orphaned parent objects

2019-10-14 Thread Mike Bayer
like Simon wrote, we would need more detail on the exact query and how you came 
up with it, in the original example it refers to an ItemGroup object "ig", is 
that the object that may have been deleted, is there a stack trace, etc.

If you can just put together a script that has the minimal mappings in use, and 
a little bit of sample data, and the steps you are doing to get to the query 
that fails, even if the script doesn't reproduce the problem I may be able to 
come up with how it would come to the stack trace you are describing (need that 
too as it shows where the problem originates).





On Mon, Oct 14, 2019, at 3:35 AM, natsjoo sodillepa wrote:
> Ok,
> 
> I have managed to get rid of the problem, but I'm don't like what is 
> happening.
> Solution: remove a secondary relation from the model:
> 
> model = relationship("Model", secondary='item_group', uselist=False)
> 
> After this, the following code does do a proper delete of the items:
> 
> for it in self.session.query(ItemMeta).filter_by(item_group=item_group).all():
> if type(it) == ItemMeta:
> item_group.items.remove(it)
> self.session.delete(it)
> self.session.commit()
> 
> However, things are still not ideal. The following should work but doesn't:
> 
> for item in item_group.items:
>  self.session.delete(item)
> 
> Then only half of the item get deleted, which is a bit weird.
> 
> Anybody any thoughts on this? Why does a secondary relation of this kind of 
> effect on a delete?
> 
> Kinde regards,
> Nacho
> 

> --
>  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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/073b7947-ed51-4b63-bfdb-a5499128c06c%40googlegroups.com
>  
> .

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/63610416-e74e-46b2-967b-4e0d24481340%40www.fastmail.com.


Re: [sqlalchemy] delete of polymorphic objects leaves orphaned parent objects

2019-10-14 Thread Simon King
I can't make a guess without a script to reproduce it I'm afraid.

Sorry,

Simon

On Mon, Oct 14, 2019 at 8:35 AM natsjoo sodillepa  wrote:
>
> Ok,
>
> I have managed to get rid of the problem, but I'm don't like what is 
> happening.
> Solution: remove a secondary relation from the model:
>
> model = relationship("Model", secondary='item_group', uselist=False)
>
>
> After this, the following code does do a proper delete of the items:
>
> for it in self.session.query(ItemMeta).filter_by(item_group=item_group).all():
> if type(it) == ItemMeta:
> item_group.items.remove(it)
> self.session.delete(it)
> self.session.commit()
>
>
> However, things are still not ideal. The following should work but doesn't:
>
> for item in item_group.items:
>self.session.delete(item)
>
> Then only half of the item get deleted, which is a bit weird.
>
> Anybody any thoughts on this? Why does a secondary relation of this kind of 
> effect on a delete?
>
> Kinde regards,
> Nacho
>
> --
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/073b7947-ed51-4b63-bfdb-a5499128c06c%40googlegroups.com.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAFHwexf05rvzhR068JJ8SYP%2BxgZmgBb-bN2V-LDSZQ8AriGU9g%40mail.gmail.com.


Re: [sqlalchemy] mssql+turbodbc cnnection not working when converted to .exe , however runs fine when it is in .py file

2019-10-14 Thread Simon King
Looks like you need to convince PyInstaller to include the turbodbc
library in your executable. This would be a PyInstaller question
rather than an SQLAlchemy one.

I haven't used PyInstaller, but typically these tools analyse your
source code to see which modules you are importing, and include those
in the executable. I suspect nothing in your application is explicitly
importing turbodbc, so PyInstaller doesn't know that it's necessary to
include it.

A quick google suggests that maybe you need to write a PyInstaller
hook (https://pyinstaller.readthedocs.io/en/stable/hooks.html) that
adds the turbodbc package to a list of hidden imports.

Hope that helps,

Simon

On Mon, Oct 14, 2019 at 6:54 AM Pradeep Dhamale
 wrote:
>
> Hi Simon,
>
> thanks for the response , following below is my code and attached is the 
> snapshot of error for your reference , the code runs fine when it is in py 
> file , however it fails when i convert it into exe.
>
>
> Code :
>
> import pandas as pd
> from pandas import DataFrame
> import numpy as np
> import pyodbc
> from sqlalchemy import create_engine
> import time
> import sqlalchemy as db
> import pymssql
> import pyodbc
> from sqlalchemy.sql import text as sa_text
> from sqlalchemy.orm import sessionmaker
> import os
> import turbodbc
>
>
> path1= "Enterpathforexcelfile"
> df=pd.read_excel(path1,'Tablename' ,ignore_index=False,index_col=False)
> df.fillna('',inplace=True)
>
> #Performaing panadas dataframe operations
>
> engine = 
> create_engine('mssql+turbodbc://:@/?driver=SQL+Server+Native+Client+10.0')
>
> connection=engine.connect()
> query="delete from Tablename;"
> engine.execute(query)
>
> #transfer dataframe to sql server
> df.to_sql('Tablename', connection, schema='schemaname',index=False 
> ,if_exists='append',chunksize=5)
>
>
>
>
>
> On Friday, October 11, 2019 at 2:37:48 AM UTC+5:30, Simon King wrote:
>>
>> What is the error message when it fails?
>>
>> On Thu, Oct 10, 2019 at 10:00 AM Pradeep Dhamale
>>  wrote:
>> >
>> > i have created a mssql connection using sqlalchemy :  mssql+turbodbc  
>> > engine,
>> > the script runs properly when it is a .py file  , however whenever i 
>> > convert the .py file to .exe using pyinstaller --one file , the exe gets 
>> > generated successfully , but while executing the exe it fails.
>> >
>> > --
>> > 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 sqlal...@googlegroups.com.
>> > To view this discussion on the web visit 
>> > https://groups.google.com/d/msgid/sqlalchemy/54ff39e6-bcff-4545-85cf-a43f9a04f1be%40googlegroups.com.
>
> --
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/a2f0dfbd-ef0f-4bba-a93b-98cbf4fcd651%40googlegroups.com.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAFHwexe_FGgEx_QxiVoT4Zu70ZvTZ8cNSDK4-kNY9WBPe%2B6z4A%40mail.gmail.com.


Re: [sqlalchemy] delete of polymorphic objects leaves orphaned parent objects

2019-10-14 Thread natsjoo sodillepa
Ok,

I have managed to get rid of the problem, but I'm don't like what is 
happening.
Solution: remove a secondary relation from the model:

model = relationship("Model", secondary='item_group', uselist=False)


After this, the following code does do a proper delete of the items:

for it in self.session.query(ItemMeta).filter_by(item_group=item_group).all():
if type(it) == ItemMeta:
item_group.items.remove(it)
self.session.delete(it)
self.session.commit()


However, things are still not ideal. The following should work but doesn't:

for item in item_group.items:
   self.session.delete(item)

Then only half of the item get deleted, which is a bit weird.

Anybody any thoughts on this? Why does a secondary relation of this kind of 
effect on a delete?

Kinde regards,
Nacho

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/073b7947-ed51-4b63-bfdb-a5499128c06c%40googlegroups.com.