cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Pardeike <andr...@pardeike.net>
Subject Inserting with a BLOB column fails
Date Fri, 19 May 2006 15:58:13 GMT
Hi,

When I try to insert a new row into my image database using this
code:

     File imgFile = new File(TEMPFILE2);
     InputStream imgStream = new FileInputStream(imgFile);
     long imgStreamLength = imgFile.length();
     byte[] imgData = new byte[(int)imgStreamLength];
     int offset = 0;
     int numRead = 0;
     while(offset < imgData.length && (numRead=imgStream.read 
(imgData, offset, imgData.length-offset)) >= 0)
        offset += numRead;
     imgStream.close();

     Images img = (Images)context.createAndRegisterNewObject 
(Images.class);
     img.setName("jei");
     img.setGroup("medarbetare");
     img.setType("image/jpeg");
     img.setX(new Integer(160));
     img.setY(new Integer(120));
     img.setImage(imgData);
     context.commitChanges();

Cayenne fails with this error:

     QueryLogger: INSERT INTO images (group, image, name, type, x, y)  
VALUES (?, ?, ?, ?, ?, ?)
     QueryLogger: [bind: 'medarbetare', < 89 50 4E 47 0D 0A 1A 0A 00  
00 00 0D ...>, 'jei', 'image/jpeg', 160, 120]
     QueryLogger: *** error.
     java.sql.SQLException: Syntax error or access violation message  
from server: "You have an error in your SQL syntax;
     check the manual that corresponds to your MySQL server version  
for the right syntax to use near 'group, image, name,
     type, x, y) VALUES ('medarbetare', _binary'‰PNG\r\n\Z\n\0\0\' at  
line 1"

Images is defined as:

     CREATE TABLE `images` (
         `name` varchar(64) NOT NULL default '',
         `group` varchar(64) NOT NULL default '',
         `type` varchar(64) NOT NULL default '',
         `image` blob NOT NULL,
         `x` int(11) NOT NULL default '0',
         `y` int(11) NOT NULL default '0',
         PRIMARY KEY  (`name`,`group`)
     ) ENGINE=MyISAM DEFAULT CHARSET=latin1

and the relevant part in Images is:

     public void setImage(byte[] image) {
         writeProperty("image", image);
     }
     public byte[] getImage() {
         return (byte[])readProperty("image");
     }


Any pointers or ideas? I already tried changing the column type but it
doesn't change anything.

Andreas Pardeike

Mime
View raw message