Re: Inserting with a BLOB column fails

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri May 19 2006 - 12:46:39 EDT

  • Next message: Gentry, Michael \(Contractor\): "RE: Caching problem?"

    A corresponding Cayenne unit test works on all version of MySQL
    between 4.0 and 5.0 (tested column type as 'longblob', but I don't
    think it matters). So what version do you have?

    Another thing to check - are you actually using MySQLAdapter (or 1.2
    auto adapter)? Is it possible there is an adapter mixup.

    Andrus

    On May 19, 2006, at 11:58 AM, Andreas Pardeike wrote:

    > 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
    >



    This archive was generated by hypermail 2.0.0 : Fri May 19 2006 - 12:47:05 EDT