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
| int verificationFTs(user)
{
int TableauFT[100];
int indexFT, i;
t_buffer *user;
MYSQL *mysql,*sock;
MYSQL_RES *res;/* Structure représentant le résultat d'une requête */
MYSQL_ROW row;/* Structure représentant les types d'une ligne de données. Lignes obtenues en appelant mysql_fetch_row() */
char *query, *pos, *str;
int j;
if ((indexFT =testmafiche(maFiche, TableauFT) )!=0)
{
// Si on a des FTs
//On recherche les FTs compatibles
for (i=0; i<indexFT; i++)
{
/* Test de connexion SQL*/
if(mysql = mysql_init(NULL))
{
if (!(sock = mysql_real_connect(mysql,"localhost","smo","smo","bugSMO",0,NULL,0)))
{
char *tmp;
TRACE1("testFTwithUsername: Couldn't connect to mysql (%s)\n",mysql_error(mysql));
tmp = "E fwcvs: Couldn't connect to the database.\n";
envoiebuf(CLNTOUTPUT,tmp,strlen(tmp));
return 0;
}
/* On lance la requête... */
query = malloc(256+user->lg);
sprintf(query,"SELECT bug_id FROM bugs b, users u WHERE b.affecte_a = u.user_id AND b.status = 2 AND u.login = '%s';",user->buf);
TRACE1("TestFTwithUsername, REQ MySQL : %s\n",query);
/* mysql_query() Exécute une requête SQL spécifiée en tant que chaîne terminée par un caractère nul.*/
if (mysql_query(sock,query))
{
char *tmp;
TRACE2("TestFTwithUsername : Couldn't select to mysql (%s)\n %s\n",mysql_error(mysql),query);
tmp = "E fwcvs: Couldn't find FT in the database.\n";
envoiebuf(CLNTOUTPUT,tmp,strlen(tmp));
free(query);
mysql_close(mysql);
return 0;
}
else
{
// test réussi on récupère le résultat de la requête dans un tableau
res = mysql_store_result(sock);
int nblignes = mysql_num_rows(res);
int test = mysql_num_fields(res);
TRACE2( "num_row = %d et num_fields = %d \n", nblignes, test);
row = mysql_fetch_row(res);
for (j = 0; j < nblignes; j++)
{
sprintf(str,"%s", row[j]);
atoi(NumFTCompatible[j], str);
TRACE1("numFTComp : %d\n",NumFTCompatible[j]);
}
for (j = 0; j < nblignes; j++)
{
if (TableauFT[j] == NumFTCompatible[j])
{
return(1);
}
else
{
return(0);
}
}
}
}
}
} |
Partager