🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #197

Ayuda con error en conexión a MySQL remota

#197
From: LucasBols
Date: Thu, 31 May 2012 19:40
126 lines
5578 bytes
Hola,

Tengo una aplicación desarrollada en C++Builder XE y uso la libmysql.dll

Cuando inserto una imagen en un campo BLOB en la base de datos local (en la misma máquina que la aplicación) la inserción se realiza correctamente, pero cuando inserto en una base de datos remota (dentro de la LAN) mysql_stmt_execute me genera este error:

"Argumentos errados para mysql_stmt_execute"

¿Qué estoy haciendo mal?

Muchas gracias por cualquier ayuda,

Este es el código del procedimiento para insertar BLOBs

bool TBaseDeDatos::AlmacenarBLOB(AnsiString cons, const char *param, unsigned long lngParam)
{
	lcl_MySQL_Error = ""; lcl_NumFilas = 0; lcl_CodError = 0;
	mysql=mysql_init(NULL);
	my_bool reconnect = 1;

	if(!mysql)
	{
		lcl_MySQL_Error = "No se pudo inicializar la base de datos: " + (AnsiString) mysql_error(mysql);
		RegError = "** " + lcl_MySQL_Error + " // " + AnsiString(__FILE__) + " // " + AnsiString(__FUNC__) + " Ln: " + IntToStr(__LINE__) + "\n";
		return false;
	}
	else
	{
		mysql_options(mysql,MYSQL_OPT_COMPRESS,0);
		mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
		mysql->reconnect = 1;
		if(!mysql_real_connect(mysql, prihost.c_str(), priusr.c_str(), pripass.c_str(), prinombd.c_str(), PuertoMYSQL, NULL, 0))
		{
			lcl_MySQL_Error = "No se pudo conectar a la base de datos: " + (AnsiString) mysql_error(mysql);
			RegError = "** " + lcl_MySQL_Error + " // " + AnsiString(__FILE__) + " // " + AnsiString(__FUNC__) + " Ln: " + IntToStr(__LINE__) + "\n";
			return false;
		}
		else
		{
			if(mysql_select_db(mysql, prinombd.c_str())) {
				lcl_MySQL_Error = "No se pudo abrir la base de datos: " + (AnsiString) mysql_error(mysql);
				RegError = "** " + lcl_MySQL_Error + " // " + AnsiString(__FILE__) + " // " + AnsiString(__FUNC__) + " Ln: " + IntToStr(__LINE__) + "\n";
				return false;
			}
			else
			{
				mysql_autocommit(mysql, TRUE);
				MYSQL_BIND		bind[1];
				MYSQL_STMT		*stmt = mysql_stmt_init(mysql);

				if(!stmt)
				{
					lcl_MySQL_Error = "No hay memoria suficiente: " + (AnsiString) mysql_error(mysql);
					RegError = "** " + lcl_MySQL_Error + " // " + AnsiString(__FILE__) + " // " + AnsiString(__FUNC__) + " Ln: " + IntToStr(__LINE__) + "\n";
					return false;
				}

				if(mysql_stmt_prepare(stmt, cons.c_str(), StrLen(cons.c_str())))
				{
					lcl_MySQL_Error = "No se pudo preparar la consulta: " + AnsiString(mysql_stmt_error(stmt));
					RegError = "** " + lcl_MySQL_Error + " // " + AnsiString(__FILE__) + " // " + AnsiString(__FUNC__) + " Ln: " + IntToStr(__LINE__) + "\n";
					return false;
				}

				memset(bind, 0, sizeof(bind));
				bind[0].buffer_type	= MYSQL_TYPE_BLOB;
				bind[0].buffer 		= (void*)param;
				bind[0].length		= &lngParam;
				bind[0].is_null		= 0;

				/* Bind the buffers */
				if(mysql_stmt_bind_param(stmt, bind))
				{
					lcl_MySQL_Error = "No se pudo enlazar el parámetro: " + AnsiString(mysql_stmt_error(stmt));
					RegError = "** " + lcl_MySQL_Error + " // " + AnsiString(__FILE__) + " // " + AnsiString(__FUNC__) + " Ln: " + IntToStr(__LINE__) + "\n";
					return false;
				}

				/* Supply the next piece of data */
				if (mysql_stmt_send_long_data(stmt, 0, (const char *)param, lngParam))
				{
					lcl_MySQL_Error = "No se pudo insertar el parámetro: " + AnsiString(mysql_stmt_error(stmt));
					RegError = "** " + lcl_MySQL_Error + " // " + AnsiString(__FILE__) + " // " + AnsiString(__FUNC__) + " Ln: " + IntToStr(__LINE__) + "\n";
					return false;
				}

				//###########################//
				//##                       ##//
				//##   ACA ESTA EL ERROR   ##//
				//##                       ##//
				//###########################//
				/* Now, execute the query */
				if (mysql_stmt_execute(stmt))
				{
					lcl_MySQL_Error = "No se pudo ejecutar la consulta : " + AnsiString(mysql_stmt_error(stmt));
					RegError = "** " + lcl_MySQL_Error + " // " + AnsiString(__FILE__) + " // " + AnsiString(__FUNC__) + " Ln: " + IntToStr(__LINE__) + "\n";
					return false;
				}
				ultimoID = mysql_insert_id(mysql);
				mysql_stmt_close(stmt);
			}
		}
		return true;
	}
}
Technical Details
Message-ID: <c386bc43-b2a6-46d1-8968-9d40d2e34f1f@googlegroups.com>
Path: arc1-ca.pugleaf.net!l9ni4788pbj.0!nntp.google.com!news2.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: f86c8,f2dc9e5a3aa6efa5,start
X-Google-NewGroupId: yes
X-Google-Attributes: gid646d03421f,domainid0,public,usenet
X-Google-Language: PORTUGUESE,ASCII
Received: by 10.68.196.232 with SMTP id ip8mr945311pbc.6.1338493590160;
        Thu, 31 May 2012 12:46:30 -0700 (PDT)
Path: arc1-ca.pugleaf.net!l9ni4788pbj.0!nntp.google.com!news2.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From: LucasBols <dnasta@gmail.com>
Newsgroups: es.comp.os.linux.programacion
Subject: Ayuda con error en conexión a MySQL remota
Date: Thu, 31 May 2012 12:40:51 -0700 (PDT)
Organization: http://groups.google.com
Lines: 126
Message-ID: <c386bc43-b2a6-46d1-8968-9d40d2e34f1f@googlegroups.com>
NNTP-Posting-Host: 200.122.67.212
Mime-Version: 1.0
X-Trace: posting.google.com 1338493590 20354 127.0.0.1 (31 May 2012 19:46:30 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 31 May 2012 19:46:30 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=200.122.67.212;
 posting-account=LYkAiAoAAACJqd9QviWQhL1sG70WXkIg
User-Agent: G2/1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable