Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > Linux Resources > LinuxForums.org - Articles
Reload this Page
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

LinuxForums.org - Articles Linux Forums Articles Archive.

 
 
Thread Tools Display Modes
Old 05-26-2005   #1 (permalink)
ravinder2000
Just Joined!
 
Join Date: May 2005
Posts: 1
From ravinderbhan2000@gmail.com


I have written a linux client in c for mysql. The values typed
in the GtkEntry widget are not getting through into the database
Here is a complete but a short version of the c client using Gtk.
There is a problem in the line 65.Interesting points which I found
while compiling and running this program are listed below.

1.I used the following command to compile the following test.c file-
root#] gcc -o test test.c -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient -lz `pkg-config --libs --cflags gtk+-2.0`
The program compiled alright.

2. When I executed the test executive file, a small window with an entry widget and a button opened up and
I put the string bb in the GtkEntry widget and pressed the INSERT button I recieved the folling output
root#] ./test
connection made.
INSERT INTO test(id) VALUES (p)
result: unknown column 'p' in 'field list'.

3. When I changed the code on line 65 into --doSQL(conn,"INSERT INTO test(id)VALUES('p')")--.and recompiled
the program and again put the string bb in the entry widget I got the following
output
connection made
INSERT INTO test(id) VALUES ('p')
result:

This time the string p got inserted into the database.

4. The problem lies with the sql query string "INSERT INTO test(id)VALUES(p)"
I want to know in the following program what form the variable p should take in the parenthesis immediatley
after the keyword VALUES. so that the insertion from the entry widget into the database coult succeed.


5 I am using Red hat Linux v9.0.

My Email is ravinderbhan2000@gmail.com


#include <gtk/gtk.h>
#include <stdlib.h>
#include <mysql.h>
#include <glib.h>


char *p;
GtkEntry *entry_box;

gint delete_event(GtkWidget *widget, GdkEvent event, gpointer data)
{
return FALSE;
}
void end_program(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
}

void doSQL(MYSQL *conn,char *command)
{
printf("%s\n",command);
mysql_query(conn,command);
printf("result: %s\n",mysql_error(conn));
}

a()

{
MYSQL *conn;
conn=mysql_init(NULL);
if(mysql_real_connect(conn,"localhost",NULL,NULL," ravi",0,NULL,0))
{
printf("connection made\n");
g_object_get(entry_box,"text",&p,NULL);
p=strdup(p);

doSQL(conn,"INSERT INTO test(id )VALUES(p)"); /*LINE NUMBER 65*/

}
}


int main(int argc, char **argv)
{
GtkWidget *window;
GtkWidget *box;
GtkButton *b;

gtk_init(&argc,&argv);
window=g_object_new(GTK_TYPE_WINDOW,"title","datae ntry widget","border-width",12,"default-width",800,NULL);
g_signal_connect(window,"delete_event",G_CALLBACK( delete_event),NULL);
g_signal_connect(window,"destroy",G_CALLBACK(end_p rogram),NULL);
box=gtk_vbox_new(FALSE,0);
entry_box=g_object_new(GTK_TYPE_ENTRY,"text","",NU LL);

b=g_object_new(GTK_TYPE_BUTTON,"label","INSERT",NU LL);
g_signal_connect(b,"clicked",G_CALLBACK(a),NULL);
gtk_container_add(GTK_CONTAINER(window),box);
gtk_box_pack_start_defaults(GTK_BOX(box),entry_box );
gtk_box_pack_start_defaults(GTK_BOX(box),b);
gtk_widget_show_all(GTK_WIDGET(window));
gtk_main();
return 0;
}
ravinder2000 is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 11:03 AM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.0.0