saving dictionaries in MySQL database with using existing connection
Hi again, I have a little problem: I have to save a dictionary object in a MySQL database. For this I have a MySQLDatabaseConnection in my folder, and I want to use this for database access. Now I don't know how I use this connection to save my dict over it. Am have succeeded in using queries with it (I can generate a query, and fire it into the database), but this is not what I intend. I want to say something like this (very, very roughly!): db.save(dictionary) ...and Zope should put my dict into the db. Serialized. Does anyone know whether this is possible or not, and if yes, how? Thanks very much in advance, Axel.
On 13 Aug 2002, Axel Bock wrote:
it into the database), but this is not what I intend. I want to say something like this (very, very roughly!): db.save(dictionary) ...and Zope should put my dict into the db. Serialized.
Does anyone know whether this is possible or not, and if yes, how?
Pickle it into a string and store the string. Unpickle it when you retreive it. But why not just store it in the zodb? --RDM
On Tue, 2002-08-13 at 20:54, R. David Murray wrote:
On 13 Aug 2002, Axel Bock wrote:
it into the database), but this is not what I intend. I want to say something like this (very, very roughly!): db.save(dictionary) ...and Zope should put my dict into the db. Serialized.
Does anyone know whether this is possible or not, and if yes, how?
Pickle it into a string and store the string. Unpickle it when you retreive it. But why not just store it in the zodb?
well, pickle is cool. :-) now I have two new problems: 1. I don't know how to get the database connection 2. I don't know how to store this string without making some queer arrangements to avoid getting \' chars in the SQL query - which are quite deadly to them. So can anyone help me with database access documentation (how to get *and use* an existing MySQLDatabaseConnection from another product, and how to store strings into it without making fuss about replacing all \' chars within the data? This would be very helpful. So thanks and greetings, Axel.
On Tue, 2002-08-13 at 18:52, Axel Bock wrote:
On Tue, 2002-08-13 at 20:54, R. David Murray wrote:
On 13 Aug 2002, Axel Bock wrote:
it into the database), but this is not what I intend. I want to say something like this (very, very roughly!): db.save(dictionary) ...and Zope should put my dict into the db. Serialized.
Does anyone know whether this is possible or not, and if yes, how?
Pickle it into a string and store the string. Unpickle it when you retreive it. But why not just store it in the zodb?
well, pickle is cool. :-)
now I have two new problems: 1. I don't know how to get the database connection
Don't try to get the database connection. It's impossible (well, not really). Instead try to realise the truth: use an sql method.
2. I don't know how to store this string without making some queer arrangements to avoid getting \' chars in the SQL query - which are quite deadly to them.
Don't bother. Let sqlvar do the quoting work for you: Add a ZMySQLDA Connector object to your site (let's call it 'conn'). Add a ZSQLMethod to your site (let's call it 'save') pointed at the 'conn' connector, with parameters: name dict and text: insert into myDictTable (dictNameColumn, dictPickleColumn) values (<dtml-sqlvar name type='string'>, <dtml-sqlvar dict type='string'>) and in your python script you just do ... container.save("my dictionary name", myDict). considerations about database schema and retrieval of the dictionary are left as an exercise for the reader. Cheers, Leo -- Ideas don't stay in some minds very long because they don't like solitary confinement.
participants (3)
-
Axel Bock -
Leonardo Rochael Almeida -
R. David Murray