No takers?  Any thoughts would be great.

--
David A. C. Beck
[EMAIL PROTECTED]
Valerie Daggett Laboratory
Biomolecular Structure and Design Program
Department of Medicinal Chemistry
University of Washington, Seattle


On Thu, 27 Jun 2002, Dave Beck wrote:

> the question:
> 
> I am trying to use the C API to insert floating (4 byte) point data into a
> mysql table.  It is very desirable to put the data in as the binary
> representation and not as a sprintf family converted string (to maintain
> precision & improve performance).  My initial attempt is below - perhaps I
> have misunderstood the usage of mysql_real_query?  I should make two notes
> on the following code: the host and source are the same machine so
> endianism is (should) not be an issue and I am also trying to insert two
> integers in the same manner.  With the code as it is I get an error in
> mysql statement.
> 
> the table description:
> +-------+---------+------+-----+---------+-------+
> | Field | Type    | Null | Key | Default | Extra |
> +-------+---------+------+-----+---------+-------+
> | frame | int     |      | MUL | 0       |       |
> | atom  | int     |      | MUL | 0       |       |
> | x     | float   |      |     | 0       |       |
> | y     | float   |      |     | 0       |       |
> | z     | float   |      |     | 0       |       |
> +-------+---------+------+-----+---------+-------+
> 
> the code:
> char  insert_format[] = "INSERT INTO %s VALUES (%hhd%hhd%hhd%hhd,
> %hhd%hhd%hhd%hhd, %hhd%hhd%hhd%hhd, %hhd%hhd%hhd%hhd,%hhd%hhd%hhd%hhd)";
> 
> int build_real_insert(char *query, char *table, int frame, int atom, float
> x, float y, float z) {
>       unsigned char   *fbp = (unsigned char *)&frame;
>       unsigned char   *abp = (unsigned char *)&atom;
>       unsigned char   *xbp = (unsigned char *)&x;
>       unsigned char   *ybp = (unsigned char *)&y;
>       unsigned char   *zbp = (unsigned char *)&z;
> 
>       return sprintf(query, insert_format, table, fbp[0], fbp[1],
> fbp[2], fbp[3], abp[0], abp[1], abp[2], abp[3], xbp[0], xbp[1], xbp[2],
> xbp[3], ybp[0], ybp[1], ybp[2], ybp[3], zbp[0], zbp[1], zbp[2], zbp[3]);
> }
> 
> in the body:
> query_len = build_real_insert(query,table_name,frame,i,x[i],y[i],z[i]);
> if(mysql_real_query(mysql,query,query_len)) {
>       // error handling
> 
> Many thanks,
>       David
> 
> --
> David A. C. Beck
> [EMAIL PROTECTED]
> Valerie Daggett Laboratory
> Biomolecular Structure and Design Program
> Department of Medicinal Chemistry
> University of Washington, Seattle
> 
> 
> 
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
> 
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail 
><[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
> 


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to