¡Hola todas y todos!
En el siguiente programa realizo dos consultas MySQL desde C. Como podrán apreciar hago una de ellas muy mal.. A saberl, la primera.
Me gustaría saber de qué modo lograr que la primera consulta sea pasada a la segunda pero no como sentencia misma, sino el resultado de mi consulta. La primera pretende estimar mis horas trabajadas en un determinado mes para devolver un valor numérico de tipo float. Pero en vez de devolver un valor numérico, traspasa toda la gigante e inacabable sentencia.
Obtengo el error:
La impresión en pantalla de
Vale decir, mi error consiste en que no toma el resultado de la suma que debería arrojar SUM (por ejemplo 63) sino el query MySQL completo en toda su gloria y majestad... pero que no me sirve en absoluto.
¿Qué estoy haciendo mal?
Acá el código completo (sin acentos en los comentarios porque aparecen garabatos y alguien puede llegar a sentirse ofendido... sin mi más mínima intensión):
Bueno, espero que puedan ayudarme...!
Saludos a todas y todos y muy agradecida por sus respuestas.
Gisi
\m/
En el siguiente programa realizo dos consultas MySQL desde C. Como podrán apreciar hago una de ellas muy mal.. A saberl, la primera.
Me gustaría saber de qué modo lograr que la primera consulta sea pasada a la segunda pero no como sentencia misma, sino el resultado de mi consulta. La primera pretende estimar mis horas trabajadas en un determinado mes para devolver un valor numérico de tipo float. Pero en vez de devolver un valor numérico, traspasa toda la gigante e inacabable sentencia.
Obtengo el error:
Código (sql) [Seleccionar]
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 'xxxx', '', 'xxxxxxxx', 'xxx', 'xxx')' at line n
La impresión en pantalla de
Código (c) [Seleccionar]
printf("Suma horas: %s", sum_horas_mensual);
(sentencia que tengo incluida en mi programa...) resulta ser:Código (sql) [Seleccionar]
Suma horas: SET @shm := (SELECT SUM(hras_trab) FROM Horas_trabajadas Total WHERE mes='Februar';)
Vale decir, mi error consiste en que no toma el resultado de la suma que debería arrojar SUM (por ejemplo 63) sino el query MySQL completo en toda su gloria y majestad... pero que no me sirve en absoluto.
¿Qué estoy haciendo mal?
Acá el código completo (sin acentos en los comentarios porque aparecen garabatos y alguien puede llegar a sentirse ofendido... sin mi más mínima intensión):
Código (c) [Seleccionar]
#include "finish_with_error.h"
#define n (10) // n = 3. Three decimal points.
//Valores que vienen traspasados de otra funcion.
void conectar(char array_fecha_fact[11], char array_fase_trabajada[257], char array_hrs_totales[4], float float_std_lohn, int int_id_empresas){
MYSQL *conn;
char q[1024],
sum_horas_mensual[4];
conn = mysql_init(NULL);
mysql_real_connect(conn, "localhost", "fact", "mi_clave_supersecreta_y_supersegura", "facturas", 0, NULL, 0);
//Aca la consulta a MySQL de la que quiero capturar el resultado y en la que hago algo mal.
sprintf(sum_horas_mensual, "SET @shm := (SELECT SUM(hras_trab) FROM Horas_trabajadas Total WHERE mes='Februar';)\n");
printf("Suma horas: %s", sum_horas_mensual);
sprintf(q,"INSERT INTO Facturas(id_fact, fecha, cant_horas, horario, hora_salario, id_empresas) VALUES('', '%s', '%s', 'algo_muy_importante_dice_aca', '%g', '%i')\n", array_fecha_fact, sum_horas_mensual, float_a, int_id_empresas);
mysql_query(conn, q);
finish_with_error(conn);
mysql_close(conn);
}
Bueno, espero que puedan ayudarme...!
Saludos a todas y todos y muy agradecida por sus respuestas.
Gisi
\m/