473,772 Members | 3,786 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_ini t(NULL);

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

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

memset(b1, 0, sizeof(b1));
b1[0].buffer_type=MY SQL_TYPE_LONG;
b1[0].buffer=(void *) &testint;
if (mysql_stmt_pre pare(s1, Q1, strlen(Q1)))
{
fprintf(stderr, " mysql_stmt_prep are(), 1 INSERT failed\n");
fprintf(stderr, " %s\n", mysql_stmt_erro r(s1));
exit(0);
}
if (mysql_stmt_bin d_param(s1, b1))
{
fprintf(stderr, " mysql_stmt_bind _param() failed\n");
fprintf(stderr, " %s\n", mysql_stmt_erro r(s1));
exit(0);
}
for (ii=0;ii<20;ii+ +)
{
testint=ii;
if (mysql_stmt_exe cute(s1))
{
fprintf(stderr, " mysql_stmt_exec ute(), 1 failed\n");
fprintf(stderr, " %s\n", mysql_stmt_erro r(s1));
exit(0);
}
}

mysql_stmt_clos e(s1);
mysql_close(mys ql);
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 1713

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

Similar topics

5
3495
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, because the dates must have quotes on each side. I just don't know how make the dates right. Well I'll just show you the code and some insert statements it generates. Could anyone please help me?
0
3527
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 form for a number of platforms from our download pages at http://www.mysql.com/downloads/ and mirror sites.
0
3948
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 version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
0
5115
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 that "#42000You have an error in your SQL syntax; ..." I tried variuos format and I get regular statement(with parameters) and stored procedure works fine in my c# code, but just not for cmd.Prepare().
9
2120
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, accented French characters, etc. I want to eliminate any potential for XSS or SQL injection attacks. My question - is it enough to pass all user input through the
4
2483
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 $flag_insert = false; $sql_insert = "INSERT IGNORE INTO table1 "; $sql_insert .= "(ID, url)"; $sql_insert .= "VALUES ";
1
2526
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
5869
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 ISO-8859-1 -t UTF-8 mydb.sql mydb_utf8.sql mysqlCREATE DATABASE mydb_utf8 CHARACTER SET utf8 COLLATE utf8_general_ci;
1
9586
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 things (stored procedures, functions).. we have to manually edit. That time, we face some interesting challenges.. I failed to document all of them, but whatever I can share with u.. I will try.. :) ...
0
9620
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9912
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.