473,379 Members | 1,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Mysql C prepared statement API sending incorrect data

I am having a problem with the C api with prepared statements, the data
recorded in the database does not match the data I am sending. It seems to
be some sort of bit shifted version of the data, and I have no idea why.

I am including code I have been using to test this, followed by the output
in the database.

I am using mysql version 4.1.12,
I have tried this on multiple servers, remote and local.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mysql/mysql.h>

#define Q1 "insert into test2 (test) values (?)"

int main ()
{
MYSQL *mysql;
/*static MYSQL_FIELD *fields;
*/
MYSQL_STMT *s1;
MYSQL_BIND b1[1];
long testint=0;
int ii;
mysql=mysql_init(NULL);

if (!mysql_real_connect(mysql, "", "", "" ,"test1",0,NULL,0))
{
fprintf(stderr, "Failed to connect to Database: Error:
%s\n",mysql_error(mysql));
exit(-1);
}

s1=mysql_stmt_init(mysql);
if (!s1)
{
fprintf(stderr, " mysql_stmt_init(), out of memory\n");
exit(-1);
}

memset(b1, 0, sizeof(b1));
b1[0].buffer_type=MYSQL_TYPE_LONG;
b1[0].buffer=(void *) &testint;
if (mysql_stmt_prepare(s1, Q1, strlen(Q1)))
{
fprintf(stderr, " mysql_stmt_prepare(), 1 INSERT failed\n");
fprintf(stderr, " %s\n", mysql_stmt_error(s1));
exit(0);
}
if (mysql_stmt_bind_param(s1, b1))
{
fprintf(stderr, " mysql_stmt_bind_param() failed\n");
fprintf(stderr, " %s\n", mysql_stmt_error(s1));
exit(0);
}
for (ii=0;ii<20;ii++)
{
testint=ii;
if (mysql_stmt_execute(s1))
{
fprintf(stderr, " mysql_stmt_execute(), 1 failed\n");
fprintf(stderr, " %s\n", mysql_stmt_error(s1));
exit(0);
}
}

mysql_stmt_close(s1);
mysql_close(mysql);
return 0;
}
mysql> select * from test2;
+------+---------+
| id | test |
+------+---------+
| 1450 | 196864 |
| 1451 | 65536 |
| 1452 | 131072 |
| 1453 | 196608 |
| 1454 | 262144 |
| 1455 | 327680 |
| 1456 | 393216 |
| 1457 | 458752 |
| 1458 | 524288 |
| 1459 | 589824 |
| 1460 | 655360 |
| 1461 | 720896 |
| 1462 | 786432 |
| 1463 | 851968 |
| 1464 | 917504 |
| 1465 | 983040 |
| 1466 | 1048576 |
| 1467 | 1114112 |
| 1468 | 1179648 |
| 1469 | 1245184 |
+------+---------+
20 rows in set (0.06 sec)

the id is just an identifier, the numbers that are supposed to be in the
test column are 0-19.
the numbers that are in the database have a difference of 65536 or 216,

Using the prepared statement api for getting data from the database works
properly as far as I can tell. So does the standard C interface, as well as
the perl and php interfaces

Any help as to what is going on here would be appreciated.

Thanks,
Oct 18 '05 #1
0 1691

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: duikboot | last post by:
Hi all, I'm trying to export a view tables from a Oracle database to a Mysql database. I create insert statements (they look alright), but it all goes wrong when I try to execute them in Mysql,...
0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
0
by: Ryan Liu | last post by:
Hi, I downloaded the latest version of mysql 5.0 and its .NET driver, I copied the sample code from mysql 5.0 manual to do use prepared statement in C#. But indeed I got a run time error say...
9
by: Harold Crump | last post by:
Greetings, I have a fairly vanilla PHP web application that stores and retrieves data in a MySQL database. Users will be adding a lot of special characters such as single and double quotes,...
4
by: TechieGrl | last post by:
Prepared statements are new to me and having to do this with a multi- dimensional array is beyond me. Here is the prepared statement block: // Prepare to insert a record into table1...
1
by: paulq182 | last post by:
PLEASE HELP ME WITH MY CODE?? import java.sql.*; import java.io.*; class min_filmdb_rel_mysql { public static void main (String args ) throws SQLException, IOException {
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
1
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.