Re: C client to load binary data to MySQL



Jens Thoms Toerring wrote:
Me Alone <me@xxxxxxxx> wrote:

<snip>

That should do exactly the same.

p = query + strlen(query);
while ((from_len = fread(buf, 1, sizeof(buf), pic)) > 0)
{
/* don't overrun end of query buffer! */
if (p + (2*from_len) + 3 > query + sizeof(query))

From a nit-picky point of view this is not 100% correct - according
to the C standard you're only allowed to compare pointers pointing
witin the same object. But in case 'p + 2 * from_len + 3' is too
large this expression already points outside of 'query'.

However, by applying a little algebra we can get a test that does not have this problem. Subtract query from both sides of the expression and we get:
if ((p - query) + (2*from_len) + 3 > sizeof(query))

This is valid on any implementation as long as both pointers are in to the same object, the difference between them can be represented and we don't have anything else causing an arithmetic overflow. Since one is unlikely to be constructing a query string anywhere even close to 30000 characters long I would say this makes it safe for all implementations without being any harder to read.

> In order
not to violate this constraint you would need to e.g. use a counter
of how much you already have used of 'query' and compare to that.
But I don't think that this is the real problem..

I agree with you. However I don't see any good reason to leave this unfixed seeing as the fix is so simple.

<snip>

if ((fromImage=load_image(mysql)) > 0)
fprintf(stderr, "%d", fromImage);

And here's definitely a problem: you call your function for putting
the image into the database (load_image() seems to be a mis-nomer for

<snip>

To the OP, if you need further help with the MySQL parts of this, such as the load_image function and connecting to the database, please take it to a suitable group, possibly one with mysql or database in its name, or the MySQL mailing lists. This group is for discussing C, not the myriads of third party libraries which have their own groups and mailing lists.
--
Flash Gordon
.



Relevant Pages

  • Re: [PHP] Problem with SELECT statement and reference material wanted..
    ... echo you query and then run it on mysql and see u getting the desired ... I'm having trouble retrieving a selection of my database contents. ... ..I will get all entries from the database, ... required to be named as the column names in the MySQL table, ...
    (php.general)
  • Ordering on Hierarchical Dot Notation
    ... I have a SQL database (MySql) containing a table with a key column which ... The problem is that this column is proving very difficult to sort naturally ... users still want to query the database using the natural representation. ...
    (comp.lang.java.databases)
  • Ordering on Hierarchical Dot Notation
    ... I have a SQL database (MySql) containing a table with a key column which ... The problem is that this column is proving very difficult to sort naturally ... users still want to query the database using the natural representation. ...
    (comp.lang.java.programmer)
  • Re: Request suggestion for query
    ... The first is a request for a suggestion of a SQL query. ... First I suggest you learn some relational database design. ... SELECT SUM(amount) as amount FROM budget WHERE member_id=1 ... Second, LIMIT is a MySQL extension, not standard SQL. ...
    (comp.databases)