Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-15-2004, 04:50 AM   #1
LQ Newbie
Registered: May 2004
Posts: 1

Rep: Reputation: 0
mysql c-api client with connection parameters at runtime

I use all Software from SUSE Linux 9.0. If I try to use connection parameters reading them at runntime I alwas have an accessviolation (Speicherzugriffsfehler) Reading the data from the mysql table is still done but with an (Speicherzugriffsfehler) at the end. Using srtcpy makes the problem. The commented version is ok.
#include <mysql/mysql.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
using namespace std;

int main()
cout << "Hello World" << endl;
MYSQL *mysql;
char *query;
int t,r;
char* db="zahlen";
unsigned int error;

printf("Error connecting\n");
}else printf("Connected ... \n");

// # # # # # # # # # # # # # #
//query="select * from nummern";
strcpy(query,"select * from nummern");
cout << "strlen(query)=" << strlen(query) << endl;
for (int i=0;i<strlen(query)+10;i++)
cout << query[i];
cout << endl << "ende query[i]" << endl;
t=mysql_real_query(mysql,query,(unsigned int) strlen(query));
printf("error quera");
}else printf("Query made \n");


while (row=mysql_fetch_row(res))
printf("%s ",row[t]);
error = mysql_errno(mysql);
cout << "myFehler: " << error << endl;

Old 05-15-2004, 07:16 AM   #2
LQ Newbie
Registered: May 2004
Location: Shah Alam
Posts: 2

Rep: Reputation: 0
char *query; /* and */ strcpy(query,"select * from nummern"); // erm...
you should first allocate a size of memory for (char *)query.
by using
query = new char[BUFSIZ]; // (++ version) or...
query = (char *)malloc(BUFSIZ * sizeof(char));

Last edited by fatah; 05-15-2004 at 07:18 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Client API I_AM Linux - Newbie 1 06-27-2005 03:52 AM
mysql client api I_AM Linux - Newbie 1 06-24-2005 12:48 AM
linking C api for mysql toships Programming 3 04-09-2004 12:29 AM
msql++ c++ api for mysql nakkaya Linux - Software 0 04-19-2003 04:56 PM
c++ and mysql api nakkaya Programming 4 03-29-2003 12:10 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:14 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration