Salut, j'ai un probleme pour insert des valeurs dans une base SQL en c !

J'ai toujours la meme erreur ki ressort alors ke je pense avoir la bonne requete ...

J'ai tester de faire la meme requete sur ma database mais la main et ca marche ...
Je me demande si ce n est pas un probleme avec mes sscanf et un pti caractere ki doit trainer...


vla le code

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
 char timestamp[5][20];
   char myid[50];
   char cattid[5];
   char number[2];
   char index[4];
   char type[4];
   char time[100];
   p1=p1+12;
   p2=p2+17;
   *p2=0;
   sscanf(p1,"%s",myid);
   p1=p1+76;
   p2=p1+5;
   *p2=0;
   sscanf(p1,"%s",catid);
   p1=p1+13;
   p2=p1;
   while (*p2!=',') {p2++;}
   *p2=0;
   sscanf(p1,"%s",number);
   p1=p2+14;
   p2=p1;
   while (*p2!=' ') {p2++;}
   *p2=0;
   sscanf(p1,"%s",timestamp[1]);
   p1=p2+1;
   while (*p2!=' ') {p2++;}
   *p2=0;
   sscanf(p1,"%s",timestamp[2]);
   p1=p2;
   p1++;
   p2=p2+3;
   *p2=0;
   sscanf(p1,"%s",timestamp[3]);
   p1=p2+1;
   p2++;
   while (*p2!=' ') {p2++;}
   *p2=0;
   sscanf(p1,"%s",timestamp[4]);
   p1=p2+1;
   while (*p2!=' ') {p2++;}
   *p2=0;
   sscanf(p1,"%s",timestamp[5]);
   p1=p2+8;
   while (*p2!='\"') {p2++;}
   *p2=0;
   sscanf(p1,"%s",index);
   p1=p2+8;
   while (*p2!=' ') {p2++;}
   *p2=0;
   sscanf(p1,"%s",type);
   p1=p2+1;
 
   sprintf(time,"%s-%s-%s-%s-%s",timestamp[1],timestamp[2],timestamp[3],timestamp[4],timestamp[5]);
   printf("Time[%s]\n",time);
   printf("Let's put it in the database! :D\n");
   sprintf(mysqlcmd,"INSERT INTO table (id,serial,type,catid,number,time,index) VALUES ('%s','%s','%s','%s','%s','%s','%s')",myid,serial,type,catid,number,time,index);
   mysql();
 
}
int mysql() {
  FILE *fp;
  int k;
 char *realquery=mysqlcmd;
  printf("Test query=[%s]\n",realquery);
  MYSQL mysql;
 
  mysql_init(&mysql);
  char host[]="kifak";
  char user[]="yalla";
  char passwd[]="passwd";
  char db[]="tamam";
  unsigned int port=3306;
  if(!mysql_real_connect(&mysql,
                          host,
                          user,
                          passwd,
                          db,
                          port,
                          NULL,
                          0))
  fprintf(stderr, "Failed to connect to database: Error: %s\n",
  mysql_error(&mysql));
  printf("Mysql Query [%s]",realquery);
  printf("Connection successfull!!\n");
  k=mysql_real_query(&mysql,realquery,sizeof(realquery));
  if (k==0) {printf("Query SuccessFuLL !! :D\n");}
  else {printf("Query FAILED !! :(\n",k);printf("Failed to query database: Error: %s\n",mysql_error(&mysql));}
}
Et voila l erreur ke mysql me sort !!

Mysql Query [INSERT INTO table (id,serial,type,catid,number,time,indexl) VALUES ('0023','00904C600023','pnt','8BAB','3','Thu-Aug-3-09:22:25-2000','-63')]

Connection successfull!!
Query FAILED !!
Failed to query database: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSE' at line 1


La query est bonne ...
mon printf renvoie ca (sans espace, sans caracteres bizarre...):

Mysql Query [INSERT INTO table (id,serial,type,catid,number,time,index) VALUES ('0023','00904C600023','pnt','8BAB','3','Thu-Aug-3-09:42:26-2000','-63')]

Vous avez un idée d ou ca peut venir ??