I cannot make the following program call the MYSQL C API when called
from the function process_token and I dont know why. I checked the WEB
and I did found nothing related to this bug. I am using slack 10, on a
x86 box with gcc. Mysql ver. 4.0.21.
Thanks in advance. Leonardo.
/*************** *************** *************** *************** **************/
#include <stdio.h>
#include <string.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xpath.h>
#include <mysql.h>
/*************** *************** *************** ********
* Errores
*************** *************** *************** ********/
#define ERR_BAD_FILE -1
#define ERR_NO_MEM -2
#define ERR_DB -3
int bDebug = 0;
char *num;
char *type;
char *year;
char *estado;
char *asunto;
char *org;
char *fecha;
char *materia;
char *pub_cod;
char *cant_art;
xmlDoc *doc = NULL;
xmlNode *rnode = NULL;
xmlNode *tag = NULL;
MYSQL *searchdb;
MYSQL *actdb;
MYSQL_RES *searchres;
MYSQL_ROW searchrow;
/*************** *************** *************** *********
* substring: simplemente saca substrings de una cadena
* inicial, pero no reasigna memoria
*************** *************** *************** *********/
char *
substring (char *orig, char *dest, int offset, int lenght)
{
sprintf (dest, "%.*s", lenght, orig + offset);
return dest;
}
int
process_token (char *token)
{
int rc = 0;
int tlen = strlen(token);
xmlChar *query = malloc (400);
sprintf (query, " SELECT id FROM keys_id LIMIT 1");
if (bDebug)
printf ("query:\n%s\n\ n", query);
rc = mysql_query(sea rchdb, query);
if (rc != 0)
{
fprintf (stderr, "No puedo buscar en la base de datos. Saliendo
\n"
"error %s\n", mysql_error (searchdb));
exit (ERR_DB);
}
searchres = mysql_use_resul t (searchdb);
searchrow = mysql_fetch_row (searchres);
if (searchrow[0])
{
xmlChar actquery[400];
memset (&actquery, 0, 400);
sprintf (actquery, "INSERT INTO keys_rel(doctyp e, emisor,
docnum, "
"emitted, docversion, key_id) VALUES('%s', '%s', "
"'%s', '%s','%d','%s') ;", type, org, num, fecha, 0,
searchrow[0]);
if (bDebug)
printf ("query de actualizacion: %s\n", actquery);
rc = mysql_real_quer y (actdb, actquery, strlen (actquery));
if (rc != 0)
{
fprintf (stderr, "No puedo actualizar la base de datos.
Saliendo.\n"
"query: %s\nerror:%s\n" , actquery, mysql_error (actdb));
exit (ERR_DB);
}
if (bDebug)
printf ("se actualizo el descriptor con el número %s\n",
searchrow[0]);
}
mysql_free_resu lt (searchres);
free (query);
return 0;
}
int
process_dsc (xmlNode * secnode)
{
xmlNode *tag = secnode->xmlChildrenNod e;
while (tag != NULL)
{
if ((!xmlStrcmp (tag->name, (const xmlChar *) "DESCRIPT") ))
{
xmlChar *token;
xmlChar *descr =
xmlNodeListGetS tring (doc, tag->xmlChildrenNod e, 1);
if (bDebug)
printf ("%s\n", descr);
token = strtok (descr, "-");
while (token)
{
process_token (token);
token = strtok (descr, "-");
}
xmlFree (descr);
}
tag = tag->next;
}
xmlFree (tag);
return 0;
}
void my_setconn (void)
{
int rc = 0;
searchdb = mysql_init (NULL);
actdb = mysql_init (NULL);
searchdb = mysql_real_conn ect (searchdb, "localhost" , "web",
NULL, "be", 0, NULL, 0);
if (!searchdb)
{
printf ("Error conectando a mysql. Saliendo.\n");
exit (ERR_DB);
}
else if (bDebug)
printf ("Estoy conectado a la primera base de datos.\n"
"el error dice %s\n", mysql_error (searchdb));
rc = mysql_select_db (searchdb, "be");
if (rc != 0)
{
printf ("Error conectando a la base de datos 'be'.
Saliendo.\n");
exit (ERR_DB);
}
actdb = mysql_real_conn ect (actdb, "localhost" , "web",
NULL, "be", 0, NULL, 0);
if (!actdb)
{
printf ("Error conectando a mysql. Saliendo.\n");
exit (ERR_DB);
}
else if (bDebug)
printf ("Estoy conectado a la segunda base de datos.\n"
"el error dice %s\n", mysql_error (actdb));
rc = mysql_select_db (actdb, "be");
if (rc != 0)
{
printf ("Error conectando a la base de datos 'be'.
Saliendo.\n");
exit (ERR_DB);
}
}
/*************** *************** *************** *********
* Procesamos las gen
*************** *************** *************** *********/
int
process_gen (xmlNode * gennode)
{
xmlNode *tag = gennode->xmlChildrenNod e;
while (tag != NULL)
{
if ((!xmlStrcmp (tag->name, (const xmlChar *) "OBS_GEN")) )
{
xmlNode *obs = tag->xmlChildrenNod e;
if ((!xmlStrcmp (obs->name, (const xmlChar *) "OBS")))
{
cant_art = malloc (7);
xmlChar *cont = xmlNodeListGetS tring (doc,
obs->xmlChildrenNod e, 1);
xmlChar *temp = strstr (cont, "ACN");
if (temp)
{
sprintf (cant_art, "%.*s", 4, temp + 4);
if (bDebug)
printf ("La cantidad de artículos de la norma es %s\n",
cant_art);
}
xmlFree (temp);
xmlFree (cont);
}
xmlFree (obs);
}
tag = tag->next;
}
xmlFree (tag);
return 0;
}
int
process_vi (xmlNode * secnode)
{
return 0;
}
static inline int
process_co (xmlNode * secnode)
{
return 0;
}
int
process_fi (xmlNode * secnode)
{
return 0;
}
int
process_an (xmlNode * secnode)
{
return 0;
}
int
process_ar (xmlNode * secnode)
{
return 0;
}
int
process_re (xmlNode * secnode)
{
return 0;
}
int
main (int argc, char **argv)
{
/* asignamos varibles de trabajo */
char *ptype = NULL;
char *ptype_rg;
/* primero checkeamos que nos hayan pasado el archivo a procesar */
if (!argv[1])
{
printf ("Uso %s <<nombre de archivo hve>> <<debug>>\n\n ",
argv[0]);
exit (0);
}
if (argv[2])
{
if (strcmp (argv[2], "debug") == 0)
bDebug = 1;
}
/*my_setconn ();*/
/* ahora parseamos el documento que tenemos como parámetro */
doc = xmlParseFile (argv[1]);
if (!doc)
{
printf ("No es posible parsear el documento %s, checkee y vuelva
"
"a intentar. Saliendo.\n\n", argv[1]);
exit (ERR_BAD_FILE);
}
if (bDebug)
printf ("se logró parsear el documento\n");
/* obtenemos el root node */
rnode = xmlDocGetRootEl ement (doc);
my_setconn();
if (rnode == NULL)
printf ("El documento esta vacío. Saliendo.\n\n") ;
else if (bDebug)
printf ("El nombre del root es %s\n", rnode->name);
/* ahora vamos por el primer field */
tag = rnode->xmlChildrenNod e;
while (tag != NULL)
{
if (ptype && ptype_rg)
{
type = strdup ("REG");
xmlFree (ptype);
xmlFree (ptype_rg);
ptype = NULL;
ptype_rg = NULL;
}
if ((!xmlStrcmp (tag->name, (const xmlChar *) "FIELD")))
{
xmlChar *fieldname = xmlGetProp (tag, "NAME");
if ((!xmlStrcmp (fieldname, "STANDARD_NORMA TIVO")))
{
if (bDebug)
printf ("se encontró el campo %s, con el valor %s\n",
fieldname, xmlNodeListGetS tring (doc,
tag->xmlChildrenNod e,
1));
}
if ((!xmlStrcmp (fieldname, "NUMERO")))
{
num = xmlNodeListGetS tring (doc, tag->xmlChildrenNod e, 1);
if (bDebug)
printf ("se encontró el campo %s, con el valor %s\n",
fieldname, num);
}
if ((!xmlStrcmp (fieldname, "ESTADO")))
{
estado = xmlNodeListGetS tring (doc, tag->xmlChildrenNod e, 1);
if (bDebug)
printf ("se encontró el campo %s, con el valor %s\n",
fieldname, estado);
}
if ((!xmlStrcmp (fieldname, "ASUNTO")))
{
asunto = xmlNodeListGetR awString (doc, tag->xmlChildrenNod e,
0);
if (bDebug)
printf ("se encontró el campo %s, con el valor %s\n",
fieldname, asunto);
}
if ((!xmlStrcmp (fieldname, "TIPO_NORMA ")))
{
ptype = xmlNodeListGetS tring (doc, tag->xmlChildrenNod e, 1);
if (bDebug)
printf ("se encontró el campo %s, con el valor %s\n",
fieldname, ptype);
}
if ((!xmlStrcmp (fieldname, "TIPO_RESOLUCIO N")))
{
ptype_rg = xmlNodeListGetS tring (doc, tag->xmlChildrenNod e, 1);
if (bDebug)
printf ("se encontró el campo %s, con el valor %s\n",
fieldname, ptype_rg);
}
if ((!xmlStrcmp (fieldname, "ORGANISMO_EMIS OR")))
{
org = xmlNodeListGetS tring (doc, tag->xmlChildrenNod e, 1);
if (bDebug)
printf ("se encontró el campo %s, con el valor %s\n",
fieldname, org);
}
if ((!xmlStrcmp (fieldname, "FECHA")))
{
xmlChar *tmp =
xmlNodeListGetS tring (doc, tag->xmlChildrenNod e, 1);
if (tmp)
{
/* alojamos espacio para un formato de fecha iso */
fecha = malloc (11);
if (!fecha)
{
perror ("imposible asignar memoria. Saliendo.\n");
exit (ERR_NO_MEM);
}
sprintf (fecha, "%.*s-%.*s-%.*s", 4, tmp, 2, tmp + 4, 2,
tmp + 6);
if (bDebug)
printf ("se encontró el campo %s, con el valor %s\n",
fieldname, fecha);
xmlFree (tmp);
}
}
if ((!xmlStrcmp (fieldname, "MAT")))
{
materia = xmlNodeListGetS tring (doc, tag->xmlChildrenNod e, 1);
if (bDebug)
printf ("se encontró el campo %s, con el valor %s\n",
fieldname, materia);
}
if ((!xmlStrcmp (fieldname, "PUBLICACION_CO DIFICADA")))
{
pub_cod = xmlNodeListGetR awString (doc, tag->xmlChildrenNod e,
1);
if (bDebug)
printf ("se encontró el campo %s, con el valor %s\n",
fieldname, pub_cod);
}
if ((!xmlStrcmp (fieldname, "TEXTO")))
{
xmlNode *seccion = tag->xmlChildrenNod e;
while (seccion != NULL)
{
if ((!xmlStrcmp (seccion->name, "S")))
{
xmlChar *tipo_seccion = xmlGetProp (seccion, "T");
if ((!xmlStrcmp (tipo_seccion, "GEN")))
process_gen (seccion);
else if ((!xmlStrcmp (tipo_seccion, "DSC")))
process_dsc (seccion);
else if ((!xmlStrcmp (tipo_seccion, "VI")))
process_vi (seccion);
else if ((!xmlStrcmp (tipo_seccion, "CO")))
process_co (seccion);
else if ((!xmlStrcmp (tipo_seccion, "RE")))
process_re (seccion);
else if ((!xmlStrcmp (tipo_seccion, "FI")))
process_fi (seccion);
else if ((xmlStrstr (tipo_seccion, "AR")))
process_ar (seccion);
else if ((xmlStrstr (tipo_seccion, "AN")))
process_an (seccion);
}
seccion = seccion->next;
}
if (bDebug)
printf ("se encontró el campo texto\n\n");
}
xmlFree (fieldname);
xmlFree (fecha);
}
tag = tag->next;
}
xmlFreeDoc (doc);
xmlCleanupParse r ();
return (0);
} 3 1809
Leonardo Javier Bel?n wrote: I cannot make the following program call the MYSQL C API when called from the function process_token and I dont know why. I checked the WEB and I did found nothing related to this bug. I am using slack 10, on a x86 box with gcc. Mysql ver. 4.0.21.
Your quoted program is very long.
For debugging a problem like this start with a very short program.
ie a progrma that connects to the db, reports whether successful
connection then closes.
As for the mysql calls, have you loaded the correct libraries?
eg MySQL-shared-4.0.21 or MySQL-shared-compat-4.0.21.
Beyond this I cant help much because *I* am having problems with the
different variations of the mysql-real-connect function!
2metre,
I have built MySQL myself from the sources, so I realized that the
libraries should be OK. The problem is that the calls on the function
process_token hang the program, while the same call in the main
function is perfectly fine, and thats why I sent such a long snipplet.
I dont know if this is a bug or a problem in my code....
Leonardo.
2metre <2m****@xxxhers ham.net> wrote in message news:<cl******* ***@sparta.btin ternet.com>... Leonardo Javier Bel?n wrote: I cannot make the following program call the MYSQL C API when called from the function process_token and I dont know why. I checked the WEB and I did found nothing related to this bug. I am using slack 10, on a x86 box with gcc. Mysql ver. 4.0.21. Your quoted program is very long.
For debugging a problem like this start with a very short program.
ie a progrma that connects to the db, reports whether successful connection then closes.
As for the mysql calls, have you loaded the correct libraries? eg MySQL-shared-4.0.21 or MySQL-shared-compat-4.0.21.
Beyond this I cant help much because *I* am having problems with the different variations of the mysql-real-connect function!
Thanks for your help but the problem was solved. The matter is that I
free a pointer I must not.
Leonardo.
2metre <2m****@xxxhers ham.net> wrote in message news:<cl******* ***@sparta.btin ternet.com>... Leonardo Javier Bel?n wrote: I cannot make the following program call the MYSQL C API when called from the function process_token and I dont know why. I checked the WEB and I did found nothing related to this bug. I am using slack 10, on a x86 box with gcc. Mysql ver. 4.0.21. Your quoted program is very long.
For debugging a problem like this start with a very short program.
ie a progrma that connects to the db, reports whether successful connection then closes.
As for the mysql calls, have you loaded the correct libraries? eg MySQL-shared-4.0.21 or MySQL-shared-compat-4.0.21.
Beyond this I cant help much because *I* am having problems with the different variations of the mysql-real-connect function! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ian.H |
last post by:
Hi all,
I've taken on a massive project for a client recently and now I've hit
some bug fixes that are required (3rd party code). and was just wondering
about peoples opinions / personal findings.
This set of scripts for the section of the project use an ADODB class for
MySQL. I've never used this method before (I wrote a class a while back to
handle my MySQL core code which was mainly a wrapper for various mysql_*()
functions etc)....
|
by: David H |
last post by:
Background.
I'm running on WinXP w/ MS Services for Unix installed (to give
rsh/rlogin ability), both Python 2.3 and 2.4 version. In linux, I'm
running RHEE with python2.3 version. The code below works fine for me
in linux, but in WinXP the popen*() command "hangs". More
specifically, I get an apparent python prompt (without the '>>> ', but
whatever I type has no effect, and hitting return does a CR but not
the additional LF, so I...
|
by: Arthur Perry |
last post by:
Hello,
I am having this problem that is just driving me crazy..
When using Bugzilla with Mysql (all Mysql, Perl, and modules all supplied by RedHat for RHEL 3.0),
MYSQL hangs frequently.
I have finally resorted to building Perl from sources once I have given up with trying to make the RedHat supplied Perl work well (using CPAN a lot here)..
I have also downloaded the pre-built binaries for MySQL AMD-64 from the MySQL website.
Now CPAN...
|
by: Sai Hertz And Control Systems |
last post by:
Dear all,
Their was a huge rore about MySQL recently for something in java functions
now theirs one more
http://www.mysql.com/doc/en/News-5.0.x.html
Does this concern anyone.
What I think is PostgreSQL would have less USP's (Uniqe Selling Points
|
by: Mairhtin O'Feannag |
last post by:
Hello,
I have a client (customer) who asked the question : "Why would I buy and
use UDB, when MySql is free?"
I had to say I was stunned. I have no experience with MySql, so I was
left sort of stammering and sputtering, and managed to pull out something
I heard a couple of years back - that there was no real transaction
safety in MySql. In flight transactions could be lost.
| |
by: Scott |
last post by:
Hi guys,
If I try to call read(), readline(), readtoend() and
there is nothing to read (from a never ending loop for
example) the program seems to continue but it exits the
loop for no apparent reason.
We also can't check the stream for the length, as the
network stream doesn't support seek operations
|
by: Grumpy Aero Guy |
last post by:
I am upgrading an app from 6.0 to VB.
Have a couple of radio buttons that gave me the "may fire when form is
initialized" upgrade message. (no problem)
Added an Isinitializing property (boolean):
----------------------------------------------------------------------------
---------
Private Property IsInitializing() As String
|
by: onnodb |
last post by:
Hi all,
While working on an Access UI to a MySQL database (which should be a
reasonable, low-cost, flexible interface to the DB, better than
web-based, much less costly than a full-fledged .NET app or so.... is
it?), I tried measuring the bandwith consumed by the
Access/MyODBC/MySQL link, which came out to be, er, quite high.
I fancied it would be interesting to look at the queries Access throws
at MySQL through the ODBC link, so I...
|
by: Ben |
last post by:
I don't know whether anyone can help, but I have an odd problem. I have
a PSP (Spyce) script that makes many calls to populate a database. They
all work without any problem except for one statement.
I first connect to the database...
self.con = MySQLdb.connect(user=username, passwd =password)
self.cursor = self.con.cursor()
self.cursor.execute("SET max_error_count=0")
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |