Re: [sqlalchemy] Interpreting a SA traceback

2023-05-24 Thread Philip Semanchuk



> On May 24, 2023, at 1:33 PM, Dan Stromberg  wrote:
> 
> I know, python2 is long dead.  We’re almost ready for Python3, but not quite.
> 
> Anyway, here’s a traceback that I’m not sure what to make of.  Is it
> saying that a transaction got so big that it couldn’t be fully flushed
> within the timeout window?  I’ve elided a sensitive part from the very
> end of the traceback.  I realize this error is coming from mysql, not
> SA.


Hi Dan,
I think you hit the nail on the head when you said "I realize this error is 
coming from mysql, not SA." It looks to me like your Python code attempted a 
commit, but some other transaction running on the server was locking the table 
that your Python code was attempting to INSERT into. Eventually MySQL noticed 
that your INSERT transaction had been in a lock wait state for too long and 
killed the INSERT transaction. SQLAlchemy is just reporting what happened.

The remedy might be to increase the lock wait timeout. I'm use Postgres, not 
MySQL, so rather than misdirecting you on how to do that, I'll let you look it 
up. Increasing the lock wait timeout might be a reasonable strategy if for some 
reason it's currently set to a very low value, but if it's not (and I expect 
the default is not low), then increasing the timeout   addresses the symptom 
rather than the disease. It's good practice not to have long running 
transactions. The first avenue I would explore is to figure out what other 
transaction was open for so long that your INSERT was locked out, and then to 
figure out why it was open for so long.


Hope this helps
Philip

-- 
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/397C4196-B144-46BF-91DB-1B4A56DD9876%40americanefficient.com.


Re: [sqlalchemy] Working with func in dates, No response, no error message

2023-03-30 Thread Philip Semanchuk



> On Mar 30, 2023, at 2:32 PM, James Paul Chibole  wrote:
> 
> Hi everyone, I am trying to retrieve deceased persons who died in the current 
> month but the output gives no result. Here is my code with query done in 
> Python Flask:
> from datetime import datetime  from 
> sqlalchemy import func  
> @app.route('/user/')@login_required 
> def user(username):
> current_month = datetime.today().date().strftime("%B")   
> monthly_anniversaries =   
> current_user.followed_deaths().filter(Deceased.burial_cremation_dat  e  
>  f_death== current_month)).order_by(Deceased.timestamp.desc())  return 
> render_template("user.html", monthly_anniversaries =monthly_anniversaries)


Flask is an extra layer of complication here that’s getting in the way of what 
you’re trying to debug. That’s not a knock on Flask (I use it too), it’s just 
not germane to a SQLAlchemy problem. My suggestion is that you try putting a 
breakpoint in your flask app so you can play with the query inside the 
debugger. Ensure that current_month is what you think it is, hardcode query 
params instead of passing variables to see if that changes results, remove some 
of the filter clauses to see if the results change the way you expect, etc.  
And of course having a look at the SQL that’s being sent to the server will 
give you some clues too, although that can be hard to get to depending on your 
environment.


Hope this helps
Philip

-- 
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/D9E83ABA-9E34-4375-A0AB-E986B96B6794%40americanefficient.com.


Re: [sqlalchemy] Relationships between different databases?

2022-08-17 Thread Philip Semanchuk



> On Aug 17, 2022, at 3:55 AM, Carl Brewer  wrote:
> 
> 
> I have three databases to work with, a PostgreSQL database on one server, and 
> two MySQL databases on another.
> 
> I've set up three different engines to connect to and reflect each one, the 
> databases and tables within don't have relationships defined in the databases 
> themselves, there's not a lot of foreign keys!
> 
> I'm wondering if it's possible to use SQLAlchemy to map out relationships 
> between them? Only within the particular bit of software I'm working on, I 
> don't expect it to export back into the databases - at the moment I'm only 
> using read-only access to the databases anyway.
> 
> Possible within the SQLAlchemy environment?


Hi Carl,
I have no experience with this so I might be making a poor suggestion, but 
Postgres’ foreign data wrappers might help you. They can expose the schema of 
other databases, so your Postgres database could be the host for all three 
databases that you need to connect to. That would make it look like one 
database to SQLAlchemy.

https://www.postgresql.org/docs/current/sql-createforeigndatawrapper.html


Good luck
Philip

-- 
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/42156053-A1EC-410E-B4CA-A7FBFF96C450%40americanefficient.com.


Re: [sqlalchemy] Problem with uploading files with flask

2022-07-25 Thread Philip Semanchuk



> On Jul 23, 2022, at 8:14 AM, ghada aissa  wrote:
> 
> Hello 
> I'm new to flask and i am trying to upload files i have as attributes 
> filename data and type(meaning extension of the file) this is my app.py code 
> :  

Hi,
Someone here might know the answer to your question, but I think you’ll have 
more luck posting this question in a Flask discussion group. This discussion 
group is for SQLAlchemy.

Cheers and good luck
Philip


-- 
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/50AECAD9-7C0C-4BA3-A636-ECA2F2FA62EE%40americanefficient.com.


Re: [sqlalchemy] simple query takes to long

2022-06-08 Thread Philip Semanchuk



> On Jun 8, 2022, at 8:29 AM, Trainer Go  wrote:
> 
> When im using pandas with pd.read_sql_query()
> with chunksize to minimiza the memory usage there is no difference between 
> both runtimes..

Do you know that, or is that speculation?

> 
> table_df = pd.read_sql_query('''select , engine, chunksize = 3)
> 
> for df in table_df:
>   print(df)
> 
> the runtime is nearly the same like 5 minutes

Printing to the screen also takes time, and your terminal probably buffers the 
results, which requires memory allocation. I’m not saying this is your problem 
(it probably isn’t), but your test still involves pandas and your terminal, 
both of which cloud the issue. You would benefit from simplifying your tests.

Did you try this suggestion from my previous email?


> for row in conn.execute(my_query).fetchall(): 
> pass 

Also, are you 100% sure you’re executing the same query from SQLAlchemy that 
you’re pasting into your DB UI?

Cheers
Philip



> 
> 
> 
> #print(table_df) result: #generator object SQLDatabase._query_iterator at 
> 0x0DC69C30>
> I dont know if the query will be triggered by using print(table_df) the 
> result is generator object SQLDatabase._query_iterator at 0x0DC69C30>
> 
> but the runtime is 6 seconds like in the DBUI im using.
> 
> I have no clue what to do.
> 
> Greetings Manuel
> 
> Trainer Go schrieb am Mittwoch, 8. Juni 2022 um 09:27:04 UTC+2:
> thank you Philip,
> 
> I will test it today.
> 
> 
> Greetings Manuel
> 
> Philip Semanchuk schrieb am Dienstag, 7. Juni 2022 um 17:13:28 UTC+2:
> 
> 
> > On Jun 7, 2022, at 5:46 AM, Trainer Go  wrote: 
> > 
> > Hello guys, 
> > 
> > Im executing 2 queries in my python program with sqlalchemy using the 
> > pyodbc driver. 
> > The database is a Adaptive SQL Anywhere Version 7 32 Bit. 
> > 
> > When im executing the queries in a DB UI it takes 5-6 seconds for both 
> > together and when im using the same queries in my python programm it takes 
> > 5-6 minutes instead of 6 seconds. What im doing wrong? Im new at this. 
> 
> To start, debug one query at a time, not two. 
> 
> Second, when you test a query in your DB UI, you’re probably already 
> connected to the database. Your Python program has to make the connection — 
> that’s an extra step, and it might be slow. If you step through the Python 
> program in the debugger, you can execute one statement at a time (the 
> connection and the query) to understand how long each step takes. That will 
> help to isolate the problem. 
> 
> Third, keep in mind that receiving results takes time too. If your DB UI is 
> written in C or some other language that allocates memory very efficiently, 
> it might be a lot faster than building a Pandas dataframe. 
> 
> You might want to eliminate Pandas entirely so you don’t have to question 
> whether or not that’s the source of your slowdown. You could do this instead 
> - 
> 
> for row in conn.execute(my_query).fetchall(): 
> pass 
> 
> That will force your Python program to iterate over the result set without 
> being forced to allocate memory for all the results. 
> 
> Hope this helps 
> Philip 

-- 
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/59C5BA30-72EF-4E26-B55D-A4AED5CCD8A4%40americanefficient.com.


Re: [sqlalchemy] simple query takes to long

2022-06-07 Thread Philip Semanchuk



> On Jun 7, 2022, at 5:46 AM, Trainer Go  wrote:
> 
> Hello guys,
> 
> Im executing 2 queries in my python program with sqlalchemy using the pyodbc 
> driver.
> The database is a Adaptive SQL Anywhere Version 7 32 Bit.
> 
> When im executing the queries in a DB UI it takes 5-6 seconds for both 
> together and when im using the same queries in my python programm it takes 
> 5-6 minutes instead of 6 seconds. What im doing wrong? Im new at this.

To start, debug one query at a time, not two.

Second, when you test a query in your DB UI, you’re probably already connected 
to the database. Your Python program has to make the connection — that’s an 
extra step, and it might be slow. If you step through the Python program in the 
debugger, you can execute one statement at a time (the connection and the 
query) to understand how long each step takes. That will help to isolate the 
problem.

Third, keep in mind that receiving results takes time too. If your DB UI is 
written in C or some other language that allocates memory very efficiently, it 
might be a lot faster than building a Pandas dataframe. 

You might want to eliminate Pandas entirely so you don’t have to question 
whether or not that’s the source of your slowdown. You could do this instead -

for row in conn.execute(my_query).fetchall():
pass

That will force your Python program to iterate over the result set without 
being forced to allocate memory for all the results.

Hope this helps
Philip






> 
> would the connection string or query help?
> And i only selecting some datas from the db and converting it into two 
> dataframes so i dont inserting, updating or deleting datas.
> 
> I hope somebody can help me.
> 
> Best regards Manuel
> 
> -- 
> 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/b306121e-913c-4ca5-bc2d-6308d76d1b76n%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/8BD49EC5-8C61-42C4-A363-C5ED7278BD7D%40americanefficient.com.


Re: [sqlalchemy] CTE w/VALUES in SELECT?

2022-02-21 Thread Philip Semanchuk



> On Feb 21, 2022, at 9:50 AM, Mike Bayer  wrote:
> 
> I thought 1.3 had "values", but if not, then you'd need to roll a recipe of 
> some kind, the original recipe is at 
> https://github.com/sqlalchemy/sqlalchemy/wiki/PGValues   

Thanks. In 1.3 sqlalchemy.sql.expression.ValuesBase exists, but it inherits 
from UpdateBase and is tied (AFAICT) to inserts and updates.


> 
> On Mon, Feb 21, 2022, at 9:06 AM, Philip Semanchuk wrote:
>> Thanks! It looks like 1.4 is required for this, correct? Any way to do this 
>> under 1.3?
>> 
>> > On Feb 20, 2022, at 8:17 PM, Mike Bayer  wrote:
>> > 
>> > the Values construct doesn't have CTE direct support right now so you need 
>> > to make a subquery first, then CTE from that
>> > 
>> > from sqlalchemy import Column
>> > from sqlalchemy import column
>> > from sqlalchemy import Integer
>> > from sqlalchemy import select
>> > from sqlalchemy import String
>> > from sqlalchemy import values
>> > from sqlalchemy.ext.declarative import declarative_base
>> > from sqlalchemy.orm import declarative_base
>> > 
>> > Base = declarative_base()
>> > 
>> > 
>> > class A(Base):
>> > __tablename__ = "my_table"
>> > 
>> > id = Column(Integer, primary_key=True)
>> > name = Column(String)
>> > 
>> > 
>> > v1 = select(
>> > values(
>> > column("name", Integer), column("color", String), name="my_values"
>> > ).data([("Lancelot", "blue"), ("Galahad", "blue. no, yellow")])
>> > ).cte()
>> > 
>> > 
>> > stmt = select(A, v1.c.color).join_from(A, v1, A.name == v1.c.name)
>> > print(stmt)
>> > 
>> > 
>> > 
>> > 
>> > On Thu, Feb 17, 2022, at 1:00 PM, Philip Semanchuk wrote:
>> >> Hi,
>> >> I'm trying to use a VALUES statement in a CTE, and I can't figure out the 
>> >> correct SQLAlchemy constructs to make this happen. I'd appreciate any 
>> >> help. Here's the SQL I'd like to express in SQLAlchemy --
>> >> 
>> >> WITH knights(name, favorite_color) AS (
>> >> VALUES
>> >> ('Lancelot', 'blue'),
>> >> ('Galahad', 'blue. no, yellow')
>> >> ),
>> >> SELECT my_table.*, favorite_color 
>> >> FROM my_table
>> >> JOIN knights USING (name)
>> >> 
>> >> Ideally, I would like to be able to express this as a Query that I can 
>> >> later execute or pass to an insert().from_select(columns, my_query).
>> >> 
>> >> The backend is Postgres 11, and our SQLAlchemy version is 1.3.
>> >> 
>> >> Thanks
>> >> Philip
>> >> 
>> >> -- 
>> >> 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/E6CA442E-CB28-431B-9056-61144A9838D2%40americanefficient.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/52b46002-1700-4fc9-b2be-fa2976edf5ef%40www.fastmail.com.
>> 
>

Re: [sqlalchemy] CTE w/VALUES in SELECT?

2022-02-21 Thread Philip Semanchuk
Thanks! It looks like 1.4 is required for this, correct? Any way to do this 
under 1.3?

> On Feb 20, 2022, at 8:17 PM, Mike Bayer  wrote:
> 
> the Values construct doesn't have CTE direct support right now so you need to 
> make a subquery first, then CTE from that
> 
> from sqlalchemy import Column
> from sqlalchemy import column
> from sqlalchemy import Integer
> from sqlalchemy import select
> from sqlalchemy import String
> from sqlalchemy import values
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy.orm import declarative_base
> 
> Base = declarative_base()
> 
> 
> class A(Base):
> __tablename__ = "my_table"
> 
> id = Column(Integer, primary_key=True)
> name = Column(String)
> 
> 
> v1 = select(
> values(
> column("name", Integer), column("color", String), name="my_values"
> ).data([("Lancelot", "blue"), ("Galahad", "blue. no, yellow")])
> ).cte()
> 
> 
> stmt = select(A, v1.c.color).join_from(A, v1, A.name == v1.c.name)
> print(stmt)
> 
> 
> 
> 
> On Thu, Feb 17, 2022, at 1:00 PM, Philip Semanchuk wrote:
>> Hi,
>> I'm trying to use a VALUES statement in a CTE, and I can't figure out the 
>> correct SQLAlchemy constructs to make this happen. I'd appreciate any help. 
>> Here's the SQL I'd like to express in SQLAlchemy --
>> 
>> WITH knights(name, favorite_color) AS (
>> VALUES
>> ('Lancelot', 'blue'),
>> ('Galahad', 'blue. no, yellow')
>> ),
>> SELECT my_table.*, favorite_color 
>> FROM my_table
>> JOIN knights USING (name)
>> 
>> Ideally, I would like to be able to express this as a Query that I can later 
>> execute or pass to an insert().from_select(columns, my_query).
>> 
>> The backend is Postgres 11, and our SQLAlchemy version is 1.3.
>> 
>> Thanks
>> Philip
>> 
>> -- 
>> 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/E6CA442E-CB28-431B-9056-61144A9838D2%40americanefficient.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/52b46002-1700-4fc9-b2be-fa2976edf5ef%40www.fastmail.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/17721A18-526A-42FC-AD2D-9FD5BA202890%40americanefficient.com.


[sqlalchemy] CTE w/VALUES in SELECT?

2022-02-17 Thread Philip Semanchuk
Hi,
I'm trying to use a VALUES statement in a CTE, and I can't figure out the 
correct SQLAlchemy constructs to make this happen. I'd appreciate any help. 
Here's the SQL I'd like to express in SQLAlchemy --

WITH knights(name, favorite_color) AS (
VALUES
('Lancelot', 'blue'),
('Galahad', 'blue. no, yellow')
),
SELECT my_table.*, favorite_color 
FROM my_table
JOIN knights USING (name)

Ideally, I would like to be able to express this as a Query that I can later 
execute or pass to an insert().from_select(columns, my_query).

The backend is Postgres 11, and our SQLAlchemy version is 1.3.

Thanks
Philip

-- 
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/E6CA442E-CB28-431B-9056-61144A9838D2%40americanefficient.com.


[sqlalchemy] Re: MySQL encoding problems

2008-07-25 Thread Philip Semanchuk

On Jul 25, 2008, at 5:34 AM, Raoul Snyman wrote:

 I'm writing a Pylons app, connecting to an existing oldish database,
 and while connecting from my Mac desktop everything is fine, but when
 I connect from our dev server, I get the following error:

 LookupError: unknown encoding: latin1_swedish_ci

 I've done some Googling, found a couple of posts on here, as well as
 elsewhere, and I'm not sure what they're talking about in those posts
 (specifically, I don't see how they solved the problem).

Hi Raoul,
I'd guess that this error is coming from Python's codecs module,  
probably indirectly from a call to unicode() with the encoding param  
set to 'latin1_swedish_ci'.

It looks like that's the default for MySQL installations:
http://dev.mysql.com/doc/refman/5.0/en/charset-we-sets.html

But Python's never heard of it:
http://docs.python.org/lib/standard-encodings.html

  import codecs
  codecs.lookup(latin1_swedish_ci)
Traceback (most recent call last):
   File stdin, line 1, in module
LookupError: unknown encoding: latin1_swedish_ci
 


So my guess is that SA is reading the encoding from the database and  
then trying to convert text fields to Unicode and getting the error  
above. Why this happens on one box and not another is mysterious. I'm  
also on a Mac and it knows nothing about latin1_swedish_ci, so I don't  
know why yours would be any different. Has your Mac Python perhaps  
been compiled with some MySQL-awareness? If you run this at the  
command line on your Mac, what does it report?

python -c import codecs; codecs.lookup('latin1_swedish_ci')


Cheers
Philip


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Implementing saved searches

2008-07-22 Thread Philip Semanchuk


On Jul 22, 2008, at 2:42 PM, Michael Bayer wrote:

 On Jul 22, 2:23 pm, Philip Semanchuk [EMAIL PROTECTED] wrote:
 I'm new to SqlAlchemy.

 I'm trying to implement saved searches, like a mail program folder
 that says, Show me all emails received yesterday, or All emails
 with 'grail' in the subject. One wrinkle is that my application
 permits user-supplied extensions, so I need to be able to define  
 saved
 searches that involve arbitrary objects/tables that I didn't code.
 This is where I think SqlAlchemy can come to my rescue. Extension
 modules will be required to define their own mappers and I'll be able
 to use those maps to query the objects without knowing much about  
 them
 in advance.

 Assuming I have code that creates a sqlalchemy.orm.query.Query object
 that describes the search I want to save, I can (almost) create a
 saved search via str(the_query.statement). I don't know where to find
 the parameters to that query, though. Can someone point me in the
 right direction? Obviously once I have the SQL + parameters it's not
 hard to save them a table somewhere.

 If anyone has done this type of thing before and has a better
 solution, I'm be happy to hear it. Storing SQL in the database seems
 inelegant, but if I'm to support searches on arbitrary objects/ 
 tables,
 I don't see a better solution.



 the binds for any SQL expression are present if you say
 statement.compile().params.  There's a little bit on this in the
 tutorial at http://www.sqlalchemy.org/docs/05/sqlexpression.html#sql_insert

Got it, thanks.


 The downside of storing SQL in the DB is that you're bound to an exact
 SQL dialect as well as table structure.   A higher level concept of
 stored filters and such would alleviate that issue but is more
 complicated to implement.  Might be worth thinking about though.   
 User-
 defined extensions would also have to provide information regarding
 their filters too.  (user-defined extension is a vague term so its
 not clear at what level these extensions are created, how strict of an
 API/sandbox they have, etc).

Thanks for your thoughts, and for SqlAlchemy.

In our app, SQLite has big advantages over other databases so I don't  
mind deepening our ties to it. It won't be going away anytime soon.  
Being bound to a specific table structure is indeed less appealing and  
that's my main objection to my proposed solution. As you point out, a  
higher level filter concept would provide a layer of abstraction and  
insulation against schema changes. To that end, I tried pickling a  
Query object but it didn't seem to like it (Can't pickle class  
'sqlalchemy.orm.properties.ColumnComparator': it's not found as  
sqlalchemy.orm.properties.ColumnComparator) which is OK. That was a  
shot in the dark, and I'm not sure it would be any wiser than just  
storing raw SQL.

bye
Philip







--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---