Good morning folks,
I cannot read a binary file into a mysql database. Everything I tried did not succeed.
What I tried (found from various google lookups...) is this:
con = MySQLdb.connect(to server)
cur = con.cursor()
cur.execute("insert into data values('file1', %s)", (open("test.jpg", "rb").read(), ))
also this doesn't work:
execute("insert into data values('file1', %s), (MySQLdb.escape_string(open("test.jpg", "rb").read()), ))
I always get this:
Warning: Data truncated for column 'file' at row 1
The blob data is actually chopped.
The Table has two columns, char(100), blob
Has someone a working idea how to get binary file into a blob using MySQLdb and python ?!
System is SuSE 10.0 Linux with python 2.5.1, current MySQLdb version, MySQL is: 5.0.26
Thanks a lot!
Greetings
Hans 4 7159
En Fri, 14 Dec 2007 12:19:41 -0300, Hans Müller <He******@web.deescribió:
I cannot read a binary file into a mysql database. Everything I tried
did not succeed.
What I tried (found from various google lookups...) is this:
con = MySQLdb.connect(to server)
cur = con.cursor()
cur.execute("insert into data values('file1', %s)", (open("test.jpg",
"rb").read(), ))
Try wrapping the file contents with a Binary object (untested):
data = MySQLdb.Binary(open("test.jpg","rb").read())
cur.execute("insert into data values('file1', %s)", (data,))
--
Gabriel Genellina
On Dec 14, 5:41 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Fri, 14 Dec 2007 12:19:41 -0300, Hans Müller <HeinT...@web.deescribió:
I cannot read a binary file into a mysql database. Everything I tried
did not succeed.
What I tried (found from various google lookups...) is this:
con = MySQLdb.connect(to server)
cur = con.cursor()
cur.execute("insert into data values('file1', %s)", (open("test.jpg",
"rb").read(), ))
Try wrapping the file contents with a Binary object (untested):
data = MySQLdb.Binary(open("test.jpg","rb").read())
cur.execute("insert into data values('file1', %s)", (data,))
--
Gabriel Genellina
I was suprised at what I could stick into a MySQL database. Also, you
might wanna compress the binary for database performance.
Hello,
thanks a lot for the Binary(). This does the trick, now I can import all my binary data.
But now I found the next problem:
The Blob is now limited to 65535 Bytes. I love all these stone age (16bit) limits on my 64bit machines...
All bigger files a truncated.
Has someone an idea how to solve this ?
Greetings
Hans
Sorry, I found the mistake:
There is more than one blob type, blob as a default stores only 64k of data.
LONGBLOB has a 4G limit which is Ok for my purposes.
Happy Christmas to all,
Hans This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Gurk |
last post by:
hi
the settings of my program are stored in an ini file, is there a simple way
to open the file in some textbox, ore a betteer soutable box.
i also want it to be able to resave the ini so...
|
by: Ivan Horvath |
last post by:
Dear All,
i would like to store binary file contents to a mysql database in a
mediumblob fields.
i've got problem when there is a simple quote, double quot, backslash or
NUL character in the...
|
by: JL |
last post by:
Platform: Linux Red Hat RHEL 3 (and red hat 9)
Installed MySQL from source. As a matter of fact, installed all LAMPS
from source, and the mysql socket file was arranged in a place other
than...
|
by: Jean Hagen |
last post by:
I'm trying to write a script to weekly remove MySQL logs, the general,
error and binary log files.
Following the MySQL documentation, I've written a script that moves all
current log files, then...
|
by: Bennett Haselton |
last post by:
I'm trying to port my MySQL tables for a database called "tracerlock" from
one server to another. On the old server, in the /var/lib/mysql/tracerlock
directory, there was a ".MYD", ".MYI" and...
|
by: David List |
last post by:
I am wondering what I miss to be able to handle binary data from the
mysql client. I have ensured that the user has file_priv set to 'Y'
and that max_allowed_packet is larger that the binary lumps...
|
by: Me Alone |
last post by:
Hello:
I am trying to edit some C code I found in "The definitive guide to
using, programming, and administering MySQL" by Paul DuBois. This C
client program connects and then segfaults when...
|
by: =?Utf-8?B?ZGF2aWQ=?= |
last post by:
I try to follow Steve's paper to build a database, and store a small text
file into SQL Server database and retrieve it later. Only difference between
my table and Steve's table is that I use NTEXT...
|
by: tech101 |
last post by:
Can I get the master (or slaves) to automatically remove the binary
logs once they are processed by all slaves?
It says in the mysql manual :
If you are using replication, you should not delete...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
| |