|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Saving pickled binary data
Hi.
I need to save pickled data in MySQL. In order to do that : 1. I am using pickling using pickle.py and the binary switch, switched to on: from pickle import * x = dumps(obj,bin=1) 2. And then trying executing SQL againt MySql DB sqlToCommit = "Update sess SET SessPageInfo = " '+x+' " where sessID ='123' ='"+sessID+"'" Unfortunately, sometimes , after serialization, I get single quote or double quotes in x. which makes the SQL invalid for MySql ( MySql "thinks" its a beggining / end of a string ) any suggestions how to do that? Thanks roy |
|
#2
|
|||
|
|||
|
The MySQLdb module has several conversion functions that will solve this problem. The most useful is escape_string(s) which will escape special characters such as single and double quotes, so it can safely be used in a SQL statement.
Incidentally, this is a recipe in the O'Reilly Python Cookbook, which I highly recommend to anyone doing serious Python development. Dave - The Developers' Coach |
|
#3
|
||||
|
||||
|
You can also use a raw string to escape data in MySQL statments although I seem to remember the MySQL module now calls escape string austomatically
. There should be a thread around here somewhere on this if you search the forums.Mark. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Saving pickled binary data |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|