-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbOp.c
66 lines (56 loc) · 1.99 KB
/
dbOp.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "headers.h"
/********************************
* Inicializar la base de datos *
* @method dbInit. *
* @param mysql pointer a DB *
********************************/
void dbInit(MYSQL *mysql) {
char *server = "localhost";
char *user = "ic15rvb";
char *password = "196190";
char *db = "ic15rvb";
mysql_init(mysql);
if (!mysql_real_connect(mysql,server,user,password,db,0,NULL,0)) {
printf("Error al conectarse a la base de datos %s\n", mysql_error(mysql));
exit(1);
}// if
if (mysql_select_db(mysql,db)) {
printf("Error al seleccionar %s\n", mysql_error(mysql));
exit(1);
}// if
}
/************************************
* Control de errores e inicializar *
* al guardar y ejecutar el comando *
* del query en res. *
* @method dbQuery *
* @param buffer query *
* @param mysql pointer a DB *
* @param res poimnter a res *
************************************/
void dbQuery(char *buffer, MYSQL *mysql, MYSQL_RES **res) {
if (mysql_query(mysql,buffer)) {
printf("Error al ejecutar query %s\n", mysql_error(mysql));
exit(1);
} // if
if (!(*res=mysql_store_result(mysql))) {
printf("Error al obtener el resultset %s\n", mysql_error(mysql));
exit(1);
} // if
}
/************************************
* Control de errores e inicializar *
* al ejecutar el comando insert. *
* @method dbQuery *
* @param buffer comando *
* @param mysql pointer a DB *
************************************/
bool dbInsert(char *buffer, MYSQL *mysql) {
bool pass = true;
if (mysql_query(mysql,buffer)) {
printf("\n\n\tERROR: %s\n", mysql_error(mysql));
printf("\tIntente de nuevo!!!\n\n");
pass = false;
} // if
return pass;
}