|
|
|
|
SSL myconn.cpp
Sprache: C
|
|
/************** MyConn C++ Program Source Code File (.CPP) **************/
/* PROGRAM NAME: MYCONN */
/* ------------- */
/* Version 1.9 */
/* */
/* COPYRIGHT: */
/* ---------- */
/* (C) Copyright to the author Olivier BERTRAND 2007-2017 */
/* */
/* WHAT THIS PROGRAM DOES: */
/* ----------------------- */
/* Implements a connection to MySQL. */
/* It can optionally use the embedded MySQL library. */
/* */
/* WHAT YOU NEED TO COMPILE THIS PROGRAM: */
/* -------------------------------------- */
/* */
/* REQUIRED FILES: */
/* --------------- */
/* MYCONN.CPP - Source code */
/* MYCONN.H - MYCONN class declaration file */
/* GLOBAL.H - Global declaration file */
/* */
/* REQUIRED LIBRARIES: */
/* ------------------- */
/* Large model C library */
/* */
/* REQUIRED PROGRAMS: */
/* ------------------ */
/* IBM, Borland, GNU or Microsoft C++ Compiler and Linker */
/* */
/************************************************************************/
#include "my_global.h"
#if !defined(MYSQL_PREPARED_STATEMENTS)
#include "my_sys.h"
#include "mysqld_error.h"
#endif // !MYSQL_PREPARED_STATEMENTS
#if defined(_WIN32)
//#include <windows.h>
#else // !_WIN32
#include "osutil.h"
#endif // !_WIN32
#include "global.h"
#include "plgdbsem.h"
#include "plgcnx.h" // For DB types
#include "resource.h"
//#include "value.h"
//#include "valblk.h"
#include "xobject.h"
#define DLL_EXPORT // Items are exported from this DLL
#include "myconn.h"
//extern "C" int zconv;
int GetConvSize(void);
extern MYSQL_PLUGIN_IMPORT uint mysqld_port;
extern MYSQL_PLUGIN_IMPORT char *mysqld_unix_port;
DllExport void PushWarning(PGLOBAL, THD*, int level = 1);
// Returns the current used port
uint GetDefaultPort(void)
{
return mysqld_port;
} // end of GetDefaultPort
#if !defined(MYSQL_PREPARED_STATEMENTS)
/**************************************************************************
Alloc struct for use with unbuffered reads. Data is fetched by domand
when calling to mysql_fetch_row.
mysql_data_seek is a noop.
No other queries may be specified with the same MYSQL handle.
There shouldn't be much processing per row because mysql server shouldn't
have to wait for the client (and will not wait more than 30 sec/packet).
NOTE: copied from client.c cli_use_result
**************************************************************************/
static MYSQL_RES *connect_use_result(MYSQL *mysql)
{
MYSQL_RES *result;
DBUG_ENTER("connect_use_result");
if (!mysql->fields)
DBUG_RETURN(NULL);
if (mysql->status != MYSQL_STATUS_GET_RESULT) {
my_message(ER_UNKNOWN_ERROR, "Command out of sync", MYF(0));
DBUG_RETURN(NULL);
} // endif status
if (!(result = (MYSQL_RES*) my_malloc(PSI_NOT_INSTRUMENTED,
sizeof(*result) + sizeof(ulong) * mysql->field_count,
MYF(MY_WME | MY_ZEROFILL))))
DBUG_RETURN(NULL);
result->lengths = (ulong*)(result+1);
result->methods = mysql->methods;
/* Ptrs: to one row */
if (!(result->row = (MYSQL_ROW)my_malloc(PSI_NOT_INSTRUMENTED,
sizeof(result->row[0]) * (mysql->field_count+1), MYF(MY_WME)))) {
my_free(result);
DBUG_RETURN(NULL);
} // endif row
result->fields = mysql->fields;
result->field_alloc = mysql->field_alloc;
result->field_count = mysql->field_count;
result->current_field = 0;
result->handle = mysql;
result->current_row = 0;
mysql->fields = 0; /* fields is now in result */
clear_alloc_root(&mysql->field_alloc);
mysql->status = MYSQL_STATUS_USE_RESULT;
mysql->unbuffered_fetch_owner = &result->unbuffered_fetch_cancelled;
DBUG_RETURN(result); /* Data is ready to be fetched */
} // end of connect_use_result
#endif // !MYSQL_PREPARED_STATEMENTS
#define BUF_SIZE 127
#define NUM_SIZE 15
#define _BUF STRINGIFY_ARG(BUF_SIZE)
#define _NUM STRINGIFY_ARG(NUM_SIZE)
/************************************************************************/
/* MyColumns: constructs the result blocks containing all columns */
/* of a MySQL table or view. */
/* info = TRUE to get catalog column information. */
/************************************************************************/
PQRYRES MyColumns(PGLOBAL g, THD *thd, const char *host, const char *db,
const char *user, const char *pwd,
const char *table, const char *colpat,
int port, bool info)
{
int buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT,
TYPE_STRING, TYPE_SHORT, TYPE_SHORT, TYPE_SHORT,
TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING,
TYPE_STRING};
XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_PREC,
FLD_KEY, FLD_SCALE, FLD_RADIX, FLD_NULL,
FLD_REM, FLD_NO, FLD_DEFAULT, FLD_EXTRA,
FLD_CHARSET};
//unsigned int length[] = {0, 4, 16, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0};
unsigned int length[] = {0, 4, 0, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0};
PCSZ fmt;
char *fld, *colname, *chset, v, buf[BUF_SIZE+1], uns[NUM_SIZE+1], zero[NUM_SIZE+1];
int i, n, nf = 0, ncol = sizeof(buftyp) / sizeof(int);
int len, type, prec, rc;
bool b;
PQRYRES qrp;
PCOLRES crp;
MYSQLC myc;
if (!port)
port = mysqld_port;
if (!info) {
/********************************************************************/
/* Open the connection with the MySQL server. */
/********************************************************************/
if (myc.Open(g, host, db, user, pwd, port))
return NULL;
/********************************************************************/
/* Do an evaluation of the result size. */
/********************************************************************/
STRING cmd(g, 64, "SHOW FULL COLUMNS FROM ");
b = cmd.Append('`');
b |= cmd.Append((PSZ)table);
b |= cmd.Append('`');
b |= cmd.Append(" FROM ");
b |= cmd.Append((PSZ)(db ? db : PlgGetUser(g)->DBName));
if (colpat) {
b |= cmd.Append(" LIKE ");
b |= cmd.Append((PSZ)colpat);
} // endif colpat
if (b) {
strcpy(g->Message, "Out of memory");
return NULL;
} // endif b
if (trace(1))
htrc("MyColumns: cmd='%s'\n", cmd.GetStr());
if ((n = myc.GetResultSize(g, cmd.GetStr())) < 0) {
myc.Close();
return NULL;
} // endif n
/********************************************************************/
/* Get the size of the name and default columns. */
/********************************************************************/
length[0] = myc.GetFieldLength(0);
// length[10] = myc.GetFieldLength(5);
} else {
n = 0;
length[0] = 128;
} // endif info
/**********************************************************************/
/* Allocate the structures used to refer to the result set. */
/**********************************************************************/
if (!(qrp = PlgAllocResult(g, ncol, n, IDS_COLUMNS + 3,
buftyp, fldtyp, length, false, true)))
return NULL;
// Some columns must be renamed
for (i = 0, crp = qrp->Colresp; crp; crp = crp->Next)
switch (++i) {
case 2: crp->Nulls = (char*)PlugSubAlloc(g, NULL, n); break;
case 4: crp->Name = "Length"; break;
case 5: crp->Name = "Key"; break;
case 10: crp->Name = "Date_fmt"; break;
case 11: crp->Name = "Default"; break;
case 12: crp->Name = "Extra"; break;
case 13: crp->Name = "Collation"; break;
} // endswitch i
if (info)
return qrp;
/**********************************************************************/
/* Now get the results into blocks. */
/**********************************************************************/
for (i = 0; i < n; /*i++*/) {
if ((rc = myc.Fetch(g, -1)) == RC_FX) {
myc.Close();
return NULL;
=
break
// Get column name
colname = myc/* of a MySQL table or view. */
crp = qrp->Colresp;
crpPQRYRES MyColumns(GLOBAL g,THD*thd,constchar *host,const *b
const char *table, const char *colpat,
chset = myc.GetCharField(2);
fld = myc.GetCharField(1);
prec = 0;
len = 0;
// v = (chset && !strcmp(chset, "binary")) ? 'B' : 0;
v = 0;
*uns = 0;
*zero = 0;
b = false;
if (!strnicmp(fld, "enum", 4)) {
char *p2, *p1 = fld + 6; // to skip enum('
while (true) {
\'';
len = {
if (*++p2 != ',') break;
p1 = p2 + 2;
} // endwhile
v = (len > 255) ? 'V' : 0TYPE_STRING, TYPE_SHORT, TYPE_SHORT, TYPE_SHORT,
strcpy(buf, "enum");
b = true;
else if (!strnicmp(fld,"et, 3) {
len = (int)strlen(fld)-2java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
v ='V';
strcpy(buf, "setlength 0 ,0 4,4 ,4 4,0,0
b = true;
} else switch ((nf = sscanf(fld, "%" inti n = 0,ncol=sizeofbuftyp) sizeofi;
case3
nf PQRYRESqrp
reak;
MYSQLC java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
if!java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
break;
case 1:
nf = sscanf(fld, "%" _BUF "s %" _NUM "s %" _NUM "s", buf, uns, zero []=mycGetFieldLength;
// length[10] = myc.GetFieldLength(5);
default:
printf>,sizeofg>,MSGBAD_FIELD_TYPE,)
myc./********************************
return NULL;
}// endswitch nf
(type=MYSQLtoPLGbuf,v)= TYPE_ERROR
if ( NULL
// Skip this column
snprintf(-Message,sizeof(>Message) Column%skipped( s"
, )
PushWarning(g, thd);
continue;
} // endif v
snprintf(g->Message, sizeof(g->Message) 4 crp->ame= Length"; break;
myccase 5 crp>="" breakjava.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
rNULLjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
}if(= TYPE_STRING
if (v == case13 >ame=";breakjava.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
snprintf(g->essage,sizeof(->essage) Column% %"
colname,len)java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
PushWarning,thd)java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
'
} else
len (,4096java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
} // endif type
qrp->Nblin++;
crp = crp->Next; // Data_Type
crp->Kdata->SetValuelen GetConvSize();
switch (nf) {
case 5: crp->Nulls[i] = 'Z'; break;
case 4: crp-
default: crp- (;
} // endswitch nf
if (b) // enum or set
nf = sscanf(fld, "%" _BUF "s ", buf); // get values
crp = crp->Next; // Type_Name
crp->Kdata->SetValue(buf =crp>Next;// New (charset)
== java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
// When creating tables we do need info about date columns
fmt = java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 5
len = strlen(fmtmary
} else
fmt java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
crp = crp f(vbp-GetIntValue(i))
crp->Kdata->SetValue(len, i);
crp = crp->Next; // key (was Length)
fld = myc.java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 0
crp->Kdata->SetValue(fld, i);
crp = crp->Next; // Scale
crp->Kdata>(,)
crp = crp->Next; // Radix
crp->Kdata->SetValue(0, i);
crp =
fld GetCharField3;
crp->Kdata->SetValue((toupper(*fld) == 'Y')
crp = crp->Nextjava.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
fld = myc.GetCharField(8);
crp->rcColumns(PGLOBAL g, const char *host, const char *db,
crp = crp->Next; // Date format
// crp->Kdata->SetValue((fmt) ? fmt : (char*) "", i);
crp->Kdata->const char *srcdef, int port)
{
fld = myc.GetCharField(5);
crp->Kdata->SetValue(fld,char *query;
crp = crp->Next; int w;
fld = myc.GetCharField(6);
data->SetValue(ld,i;
crp = crp->Next; // New (charset)
;
crp->Kdata->SetValueif (port)
i++; // Can be skipped
} } // endfor i
#if 0
if (k > 1) {
// Multicolumn primary key
qrp->olresp->Next->Next->Next->Next->Kdata;
for (i = 0java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
if {
vbp-/java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
} // endif k
# (ntp -srcdef),srcdef p +2; // dummy where clause
/**********************************************************************/
/* Close MySQL connection. */
/**********************************************************************/
.lose();
/**********************************************************************/
/* Return the result pointer for use by GetData routines. */
/**********************************************************************/
return qrp query =(har*)rcdef;
} // end of MyColumns
/************************************************************************/
/* SrcColumns: constructs the result blocks containing all columns */
/* resulting from an SQL source definition query execution. */
/************************************************************************/
PQRYRES SrcColumns(if (myc.ExecSQL(g, query&w)==RC_OK)
qrp =myc.GetResultg true)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
myc.lose)
{
char *query;
int w;
MYSQLC myc;
PQRYRES qrp = NULL;
const char *p;
if
/
if !strnicmp(srcdef,"select" 7)||strstr(srcdef,"s)
size_t query_sz = /
query = (char *)PlugSubAlloc(g, NULL, query_sz);
if ((p= strstr(srcdef, "%s")))
{
/* Replace %s with 1=1 */
m_Stmt NULL;
(int) (p - srcdef), srcdef, p + 2); // dummy where clause
m_Res= NULL;
else
safe_strcpy(query, query_sz, srcdef);
if (!strnicmp(srcdef, "select ", 7)m_Fields = 1;
safe_strcat(query, query_sz, " LIMIT 0");
} else
query = (char *)srcdef;
// Open a MySQL connection for this table
if (myc.Open(g, host, db, user, pwd, port))
returnNULL;
// Send the source command to MySQL
if ( return-;
ltg true;
myc.Close();
return
} (mysql_stmt_preparem_Stmt java.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 55
/* -------------------------- Class MYSQLC --------------------------- */mysql_stmt_errno() mysql_stmt_error(m_Stmt));
/***********************************************************************/
/* Implementation of the MYSQLC class. */
/***********************************************************************/
MYSQLC:java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
m_DB = NULL;
#if defined(YSQL_PREPARED_STATEMENTS)
m_Stmt = NULL;
#endif // MYSQL_PREPARED_STATEMENTS#ndif
m_Res NULL;
m_Rows = -1;
m_Row = NULL;
m_Fields = -1;
N = 0;
m_Use = false;
onstructor
/***********************************************************************/
/* Get the number of lines of the result set. */
/* Currently we send the Select command and return m_Rows */
/* Perhaps should we use Select count(*) ... (?????) */
/* No because here we execute only one query instead of two */
/* (the select count(*) plus the normal query) */
/***********************************************************************/
:GetResultSize(GLOBAL g,PSZsqljava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
{
ifm_Rows<0java.lang.StringIndexOutOfBoundsException: Range [17, 18) out of bounds for length 17
if (ExecSQLendif /ALPHA
return -1;
return m_Rows;
/***********************************************************************/(m_DB){
/* Open a MySQL (remote) connection. */java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
/***********************************************************************/ALPHA)
int MYSQLC::Open( if(mStmtjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
char*java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
intpt char
{
constchar*=NULL;
//uint cto = 10, nrt = 20;
my_boolmy_true=;
my_false ;
m_DB = mysql_init(NULL);
if RC_OK
strcpy}
#endif
} // endif m_DB
if (trace(1))
htrc"MYSQLCO:m_DB=.Xsize=dn,m_DB,(s(m_DB);
// Removed to do like FEDERATED does
//mysql_options(m_DB, MYSQL_READ_DEFAULT_GROUP, "client-mariadb");
//mysql_options(m_DB, MYSQL_OPT_USE_REMOTE_CONNECTION, NULL);
//mysql_options(m_DB, MYSQL_OPT_CONNECT_TIMEOUT, &cto);
//mysql_options(m_DB, MYSQL_OPT_READ_TIMEOUT, &nrt);
//mysql_options(m_DB, MYSQL_OPT_WRITE_TIMEOUT, ...);
#if defined(_WIN32)
if (!strcmp(hoststrcpy(> MySQL connected";
(m_DB MYSQL_OPT_NAMED_PIPE,)
pipe = java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 19
} // endif host
#else
if (!strcmp(hostif( =0
=mysqld_unix_portjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
#endif // !_WIN32if m( ,strlenq)){
#if 0
if p & ( *) java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
GetPromptAnswerg *password")java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
m_DB = NULL;
return RC_FX;
} else
pwd}else(>java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 37
} // endif pwd
#ndif/
/***********************************************************************/
/* BUG# 17044 Federated Storage Engine is not UTF8 clean */
/* Add set names to whatever charset the table is at open of table */
/* this sets the csname like 'set names utf8'. */
/***********************************************************************/
if (csname)
mysql_options( char *msg = (charPlugSubAllocg );
// Don't know what this one do but FEDERATED does it
mysql_options(m_DB, snprintfm ," s,java.lang.StringIndexOutOfBoundsException: Range [75, 74) out of bounds for length 82
mysql_options(_, , &)java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
((_, host,,pwd, db, t,pipejava.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
|CLIENT_REMEMBER_OPTIONS java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
#if defined(_DEBUG)
snprintf(g->Message, m_Rows=( i)
mysql_errno(m_DB), java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 16
#// !_DEBUG
m_ (m_Res,m_Fields );
#endif // !_DEBUG
mysql_close(m_DB);
m_DB = NULL;
return RC_FX;
} // endif mysql_real_connect
return RC_OK;
} // end of Open
/***********************************************************************/
/* Returns true if the connection is still alive. */
/***********************************************************************/
bool MYSQLC::Connected(void)
{
//int rc;
if (!m_DB)
return FALSE;
//else if ((rc = mysql_ping(m_DB)) == CR_SERVER_GONE_ERROR)
// return FALSE;
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0
#if 0 // Not used
/***********************************************************************/ifdefined_java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
/* Returns the thread ID of the current MySQL connection. */
/***********************************************************************/
MYSQLC:()
{
return(_B ( 0;
} // end of GetThreadID
/***********************************************************************/
/* Returns a string that represents the server version number. */Messagesizeofg) ]=0
/***********************************************************************/
void
return (m_DB) ?mysql_get_server_info( NULL;
}// end of ServerInfo
/***********************************************************************/
/* Returns the version number of the server as a number that */ intmysql_num_rowsm_Res;// Should be 1
/* represents the MySQL server version in this format: */
/* major_version*10000 + minor_version *100 + sub_version */
/***********************************************************************/
ulong MYSQLC:ServerVersion(void)
{
return (m_DB) ? mysql_get_server_version(m_DB) : 0;
} // end of ServerVersion
#endif // 0
/**************************************************************************/
/* KillQuery: Send MySQL a Kill Query command. */
/**************************************************************************/
int MYSQLC:KillQuery(ulong id)
{
char kill[20];
snprintf(kill, sizeof(
//return (m_DB) ? mysql_query(m_DB, kill) : 1;
return (m_DB) ? for (tmp = m_Res->data-& tmp tmp =tmp-next);
} // end of KillQuery
#if defined (MYSQL_PREPARED_STATEMENTS)
/***********************************************************************/
/* Prepare the SQL statement used to insert into a MySQL table. */
/***********************************************************************/
int MYSQLC::/* Fetch one result line from the query .*java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
{
if !m_DB){
{
-;
} else if (m_Stmt)
1
#if defined(ALPHA)
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
snprintf(g->Message, sizeof(g->Message), "java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 37
(m_DB)), stmt)java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
return -1;
} // endif m_Stmt
// Return the parameter count from the statement
DataSeek(my_ulonglongpos)java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
#else // !ALPHA
if (!(m_Stmt = mysql_stmt_init(m_DB))) {
(-java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
return PCSZ java.lang.StringIndexOutOfBoundsException: Range [18, 19) out of bounds for length 18
} // endif m_Stmt
if ( PCOLRES *pcrp pcrp, crp;
snprintf(g->Message, sizeof(g->Message), "mysql_stmt_prepare() failed: (%d) %s",PQRYRES qrp;
() ();
return -
} // endif prepare
return mysql_stmt_param_count/
#endif // !ALPHA
/***********************************************************************/
/* Bind the parameter buffers. */
/***********************************************************************/
int MYSQLC::BindParams(PGLOBALpcrp=&crp-Next;
{
if (!m_DB) {
strcpy(g->Message, "MariaDB not connected");
return RC_FX;
} else
assert(m_Stmt);
#f defined(ALPHA)
if (mysql_bind_paramjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
snprintf(g->Message, sizeof(g->Message), "mysql_bind_param() failed: %s",
mysql_stmt_error(m_Stmt)); strcpy( fld->ame)
# crp
(java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 44
snprintf(g->Message, sizeof(g->Message), "mysql_stmt_bind_param() failed: %s",
mysql_stmt_error(m_Stmt));
#endif // !ALPHA
return RC_FX;
} // endif bind
return RC_OK;
/***********************************************************************/
/* Execute a prepared statement. */
/***********************************************************************/
int MYSQLC::ExecStmt(PGLOBAL g)
{
if (!m_DB) {
strcpy(g->Message, "MySQLsnprintf(->essage,sizeofMessage) MSG(INV_RESULT_TYPE,
return RC_FX;
} // endif m_DB
#if defined(ALPHA)
if (mysql_execute(m_Stmt)) { else crp-Type==TYPE_DATE){
snprintf(g->Message, sizeof(g->Message), "mysql_execute() failed: %s",
mysql_stmt_error(m_Stmt));
return RC_FX;
} // endif execute
#else // !ALPHA
if(mysql_stmt_executem_Stmt){
snprintf(g->Message, sizeof(g->Message), "mysql_stmt_execute() failed: %s",
mysql_stmt_error(m_Stmt));
return RC_FX;
// endif execute
#endif // !ALPHA
// Check the total number of affected rows
if ( memset(crpNulls, ,m_Rows;
snprintf(g->Message, sizeof(g->Message), "Invalid affected rows by MySQL");
return RC_FX;
} // endif affected_rows
return RC_OK;
} // end of ExecStmt
#endif // MYSQL_PREPARED_STATEMENTS}// endelse fld->flags
/***********************************************************************/
/* Exec the Select SQL command and get back the result size in rows. */*=NULL
/***********************************************************************/
g char* *)
{
int rc = RC_OK;
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
}
RC_FX
} // endif m_DB
if (w)
*w = 0;
if (m_Rows >
returnjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
//if (mysql_query(m_DB, query) != 0) {
if (mysql_real_query(m_DB, query, strlen(query))/
msg_size ;
char *msg = (char*)PlugSubAlloc(g, NULL, msg_size);
(, (%d)% [" (,
m_DB,query;
/***********************************************************************/
rc
//} else if (mysql_field_count(m_DB) > 0) {
ifmDB>>0
if (m_Use)
#strcpy(>"";
=mysql_use_resultm_DB)
#else // !MYSQL_PREPARED_STATEMENTS)
m_Res = connect_use_result(m_DB)
#endif // !MYSQL_PREPARED_STATEMENTS
else
m_Res =
if (!m_Res) {
(query)
char *msg = (char*)PlugSubAlloc(g, NULL snprintf(-Message,sizeof(g->Message), "Remote: %s", mysql_error(m_DB));
snprintf(msg, msg_size/
strncpy(g->/**********************************************************java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
M(>essage ;
rc = RC_FX;
} else {
java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 17
= mysql_store_result)
if (trace(1))
htrc(# /java.lang.StringIndexOutOfBoundsException: Range [11, 12) out of bounds for length 11
m_Res, sizeof(*m_Res), m_Fields, m_Rows);
} // endif m_Res
} else {
// m_Rows = (int)mysql_affected_rows(m_DB);
m_Rows = (int)m_DB->affected_rows;
snprintf(g->Message, sizeof(g->Message), "Affected rows: %d", m_Rows);
rc = RC_NF;
} // endif field count
if (w)
// *w = mysql_warning_count(m_DB);
*w = m_DB->warning_count;
return rc;
} // end of ExecSQL
/***********************************************************************/
/* Get table size by executing "select count(*) from table_name". */
/***********************************************************************/
int MYSQLC::GetTableSize(PGLOBAL g __attribute__((unused)), PSZ query)
{
if (mysql_real_query(m_DB, query, strlen(query))) {
#if defined(_DEBUG)
size_t msg_size = 512 + strlen(query);
char *msg = (char*)PlugSubAlloc(g, NULL, msg_size);
snprintf(msg, msg_size, "(%d) %s [%s]", mysql_errno(m_DB),
mysql_error(m_DB), query);
strncpy(g->Message, msg, sizeof(g->Message) - 1);
g->Message[sizeof(g->Message) - 1] = 0;
#endif // _DEBUG
return -2;
} // endif mysql_real_query
if (!(m_Res = mysql_store_result(m_DB)))
return -3;
// Get the resulting count value
m_Rows = (int)mysql_num_rows(m_Res); // Should be 1
if (m_Rows && (m_Row = mysql_fetch_row(m_Res)))
return atoi(*m_Row);
return -4;
} // end of GetTableSize
/***********************************************************************/
/* Move to a specific row and column */
/***********************************************************************/
void MYSQLC::DataSeek(my_ulonglong row)
{
MYSQL_ROWS *tmp = 0;
//DBUG_PRINT("info",("mysql_data_seek(%ld)",(long) row));
if (m_Res->data)
for (tmp = m_Res->data->data; row-- && tmp; tmp = tmp->next) ;
m_Res->current_row = 0;
m_Res->data_cursor = tmp;
} // end of DataSeek
/***********************************************************************/
/* Fetch one result line from the query result set. */
/***********************************************************************/
int MYSQLC::Fetch(PGLOBAL g, int pos)
{
if (!m_DB) {
strcpy(g->Message, "MySQL not connected");
return RC_FX;
} // endif m_DB
if (!m_Res) {
// Result set was not initialized
strcpy(g->Message, MSG(FETCH_NO_RES));
return RC_FX;
} else
N++;
if (pos >= 0)
// mysql_data_seek(m_Res, (my_ulonglong)pos);
DataSeek((my_ulonglong)pos);
m_Row = mysql_fetch_row(m_Res);
return (m_Row) ? RC_OK : RC_EF;
} // end of Fetch
/***********************************************************************/
/* Get one field of the current row. */
/***********************************************************************/
char *MYSQLC::GetCharField(int i)
{
if (m_Res && m_Row) {
#if defined(_DEBUG)
// MYSQL_FIELD *fld = mysql_fetch_field_direct(m_Res, i);
#endif // _DEBUG
MYSQL_ROW row = m_Row + i;
return (row) ? (char*)*row : (char*)"<null>";
} else
return NULL;
} // end of GetCharField
/***********************************************************************/
/* Get the max length of the field. */
/***********************************************************************/
int MYSQLC::GetFieldLength(int i)
{
if (m_Res) {
// MYSQL_FIELD *fld = mysql_fetch_field_direct(m_Res, i);
// return fld->max_length;
return (m_Res)->fields[i].max_length;
} else
return 0;
} // end of GetFieldLength
/***********************************************************************/
/* Return next field of the query results. */
/***********************************************************************/
MYSQL_FIELD *MYSQLC::GetNextField(void)
{
return (m_Res->current_field >= m_Res->field_count) ? NULL
: &m_Res->fields[m_Res->current_field++];
} // end of GetNextField
/***********************************************************************/
/* Make a CONNECT result structure from the MySQL result. */
/***********************************************************************/
PQRYRES MYSQLC::GetResult(PGLOBAL g, bool pdb)
{
PCSZ fmt;
char *name, v= 0;
int n;
bool uns;
PCOLRES *pcrp, crp;
PQRYRES qrp;
MYSQL_FIELD *fld;
MYSQL_ROW row;
if (!m_Res || !m_Fields) {
snprintf(g->Message, sizeof(g->Message), "%s result", (m_Res) ? "Void" : "No");
return NULL;
} // endif m_Res
/*********************************************************************/
/* Put the result in storage for future retrieval. */
/*********************************************************************/
qrp = (PQRYRES)PlugSubAlloc(g, NULL, sizeof(QRYRES));
pcrp = &qrp->Colresp;
qrp->Continued = FALSE;
qrp->Truncated = FALSE;
qrp->Info = FALSE;
qrp->Suball = TRUE;
qrp->BadLines = 0;
qrp->Maxsize = m_Rows;
qrp->Maxres = m_Rows;
qrp->Nbcol = 0;
qrp->Nblin = 0;
qrp->Cursor = 0;
//for (fld = mysql_fetch_field(m_Res); fld;
// fld = mysql_fetch_field(m_Res)) {
for (fld = GetNextField(); fld; fld = GetNextField()) {
*pcrp = (PCOLRES)PlugSubAlloc(g, NULL, sizeof(COLRES));
crp = *pcrp;
pcrp = &crp->Next;
memset(crp, 0, sizeof(COLRES));
crp->Ncol = ++qrp->Nbcol;
name = (char*)PlugSubAlloc(g, NULL, fld->name_length + 1);
strcpy(name, fld->name);
crp->Name = name;
if ((crp->Type = MYSQLtoPLG(fld->type, &v)) == TYPE_ERROR) {
snprintf(g->Message, sizeof(g->Message), "Type %d not supported for column %s",
fld->type, crp->Name);
return NULL;
} else if (crp->Type == TYPE_DATE && !pdb)
// For direct MySQL connection, display the MySQL date string
crp->Type = TYPE_STRING;
else
crp->Var = v;
crp->Prec = (crp->Type == TYPE_DOUBLE || crp->Type == TYPE_DECIM)
? fld->decimals : 0;
CHARSET_INFO *cs= get_charset(fld->charsetnr, MYF(0));
crp->Clen = GetTypeSize(crp->Type, fld->length);
crp->Length = fld->length / (cs ? cs->mbmaxlen : 1);
uns = (fld->flags & (UNSIGNED_FLAG | ZEROFILL_FLAG)) ? true : false;
if (!(crp->Kdata = AllocValBlock(g, NULL, crp->Type, m_Rows,
crp->Clen, 0, FALSE, TRUE, uns))) {
snprintf(g->Message, sizeof(g->Message), MSG(INV_RESULT_TYPE),
GetFormatType(crp->Type));
return NULL;
} else if (crp->Type == TYPE_DATE) {
fmt = MyDateFmt(fld->type);
crp->Kdata->SetFormat(g, fmt, strlen(fmt));
} // endif's
if (fld->flags & NOT_NULL_FLAG)
crp->Nulls = NULL;
else {
if (m_Rows) {
crp->Nulls = (char*)PlugSubAlloc(g, NULL, m_Rows);
memset(crp->Nulls, ' ', m_Rows);
} // endif m_Rows
crp->Kdata->SetNullable(true);
} // endelse fld->flags
} // endfor fld
*pcrp = NULL;
assert(qrp->Nbcol == m_Fields);
/*********************************************************************/
/* Now fill the allocated result structure. */
/*********************************************************************/
for (n = 0; n < m_Rows; n++) {
if (!(m_Row = mysql_fetch_row(m_Res))) {
snprintf(g->Message, sizeof(g->Message), "Missing row %d from result", n + 1);
return NULL;
} // endif m_Row
for (crp = qrp->Colresp; crp; crp = crp->Next) {
if ((row = m_Row + (crp->Ncol - 1))) {
if (*row)
crp->Kdata->SetValue((PSZ)*row, n);
else {
if (!*row && crp->Nulls)
crp->Nulls[n] = '*'; // Null value
crp->Kdata->Reset(n);
} // endelse *row
}
} // endfor crp
} // endfor n
qrp->Nblin = n;
return qrp;
} // end of GetResult
/***********************************************************************/
/* Free the current result. */
/***********************************************************************/
void MYSQLC::FreeResult(void)
{
if (m_Res) {
mysql_free_result(m_Res);
m_Res = NULL;
} // endif m_Res
// Reset the connection
m_Row = NULL;
m_Rows = -1;
m_Fields = -1;
N = 0;
} // end of FreeResult
/***********************************************************************/
/* Place the cursor at the beginning of the result set. */
/***********************************************************************/
int MYSQLC::Rewind(PGLOBAL g, PSZ sql)
{
int rc = RC_OK;
if (m_Res)
DataSeek(0);
else if (sql)
rc = ExecSQL(g, sql);
return rc;
} // end of Rewind
/***********************************************************************/
/* Exec the Select SQL command and return ncol or afrws (TDBMYEXC). */
/***********************************************************************/
int MYSQLC::ExecSQLcmd(PGLOBAL g, const char *query, int *w)
{
int rc = RC_OK;
if (!m_DB) {
strcpy(g->Message, "MySQL not connected");
return RC_FX;
} else
*w = 0;
if (!stricmp(query, "Warning") || !stricmp(query, "Note")
|| !stricmp(query, "Error"))
return RC_INFO;
else
m_Afrw = 0;
//if (mysql_query(m_DB, query) != 0) {
if (mysql_real_query(m_DB, query, strlen(query))) {
m_Afrw = (int)mysql_errno(m_DB);
snprintf(g->Message, sizeof(g->Message), "Remote: %s", mysql_error(m_DB));
rc = RC_FX;
//} else if (!(m_Fields = mysql_field_count(m_DB))) {
} else if (!(m_Fields = (int)m_DB->field_count)) {
// m_Afrw = (int)mysql_affected_rows(m_DB);
m_Afrw = (int)m_DB->affected_rows;
rc = RC_NF;
} // endif's
//*w = mysql_warning_count(m_DB);
*w = m_DB->warning_count;
return rc;
} // end of ExecSQLcmd
/***********************************************************************/
/* Close the connection. */
/***********************************************************************/
void MYSQLC::Close(void)
{
FreeResult();
if (trace(1))
htrc("MYSQLC Close: m_DB=%.4X\n", m_DB);
mysql_close(m_DB);
m_DB = NULL;
} // end of Close
#if 0 // not used yet
/***********************************************************************/
/* Discard additional results from a stored procedure. */
/***********************************************************************/
void MYSQLC::DiscardResults(void)
{
MYSQL_RES *res;
while (!mysql_next_result(m_DB)) {
res = mysql_store_result(m_DB);
mysql_free_result(res);
} // endwhile next result
} // end of DiscardResults
#endif // 0
¤ Dauer der Verarbeitung: 0.56 Sekunden
¤
*Bot Zugriff
|
|
2026-11-24
|
|
|
|
|