-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebird.c
50 lines (48 loc) · 1.46 KB
/
firebird.c
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
#include <libfb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <netdb.h>
void funcionFirebird(char user[], char pwd[], char db[], char rol[], int idsockc,char consulta[], char *response)
{
int i,j;
memset(response,0,20000);
extern int FB_SHOW_MESSAGES; // 1 activa/ 0 desactiva los mensajes de libreria FB
FB_SHOW_MESSAGES = 1; // desactivo mensajes de libreria libfb
fb_db_info dbinfo;
strcpy(dbinfo.user,user);
strcpy(dbinfo.passw,pwd);
strcpy(dbinfo.dbname,db);
strcpy(dbinfo.role,rol);
if (fb_do_connect(&dbinfo)) {
query myquery;
fb_init(&myquery);
if ( fb_do_query(&dbinfo,1,consulta,onDoGenericQuery,&myquery) ) {
rquery *q = myquery.top; // primer tupla del query
char **cols;
while (q) {
cols = (char **) q->col; // q->col arreglo de apuntadores a char *
for(i=0; i < myquery.rows_fetched; i++){
for(j=0; j < myquery.cols; j++){
strcat(response, fb_get_col(&myquery, q, j));
strcat(response,"//");
}
strcat(response,".\n");
write(idsockc,response,20000);
memset(response,0,20000);
q = q->next; // siguiente tupla del query
}
}
fb_free(&myquery);
} else {
printf("Error en ejecucion\n\
Error FB [%d] mensaje [%s] sql code [%ld]\n",myquery.fb_error,myquery.errmsg,myquery.SQLCODE);
}
fb_do_disconnect(&dbinfo);
}
}