Skip to content

Commit

Permalink
- Fix MDEV-11234. Escape quoting character. Should be doubled.
Browse files Browse the repository at this point in the history
  Now it is also possible to escape it by a backslash.
  modified:   storage/connect/tabfmt.cpp

- Prepare making VEC table type support conditional.
  VEC tables might be unsupported in future versions
  modified:   storage/connect/CMakeLists.txt
  modified:   storage/connect/mycat.cc
  modified:   storage/connect/reldef.cpp
  modified:   storage/connect/xindex.cpp

- MDEV-11067 suggested to add configuration support to the Apache wrapper.
  Was added but commented out until prooved it is really useful.
  modified:   storage/connect/ApacheInterface.java
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/jdbccat.h
  modified:   storage/connect/jdbconn.cpp
  modified:   storage/connect/jdbconn.h
  modified:   storage/connect/tabjdbc.cpp
  modified:   storage/connect/tabjdbc.h

- Remove useless members.
  modified:   storage/connect/jdbconn.cpp
  modified:   storage/connect/jdbconn.h

- New UDF countin.
  modified:   storage/connect/jsonudf.cpp
  modified:   storage/connect/jsonudf.h
  • Loading branch information
Buggynours committed Nov 6, 2016
1 parent b7aee7d commit 5884aa1
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 50 deletions.
5 changes: 4 additions & 1 deletion storage/connect/ApacheInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
ds.setPassword(parms[3]);
pool.put(url, ds);
} // endif ds


// if (parms.length > 4 && parms[4] != null)
// ds.setConnectionProperties(parms[4]);

// Get a connection from the data source
conn = ds.getConnection();

Expand Down
2 changes: 1 addition & 1 deletion storage/connect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ user_connect.h valblk.h value.h xindex.h xobject.h xtable.h)
# Definitions that are shared for all OSes
#
add_definitions( -DMARIADB -DFORCE_INIT_OF_VARS -Dconnect_EXPORTS)
add_definitions( -DHUGE_SUPPORT -DZIP_SUPPORT -DPIVOT_SUPPORT )
add_definitions( -DHUGE_SUPPORT -DZIP_SUPPORT -DPIVOT_SUPPORT -DVCT_SUPPORT )


#
Expand Down
7 changes: 5 additions & 2 deletions storage/connect/ha_connect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
#define JSONMAX 10 // JSON Default max grp size

extern "C" {
char version[]= "Version 1.04.0008 August 10, 2016";
char version[]= "Version 1.04.0008 October 20, 2016";
#if defined(__WIN__)
char compver[]= "Version 1.04.0008 " __DATE__ " " __TIME__;
char slash= '\\';
Expand Down Expand Up @@ -5190,7 +5190,8 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
PJPARM sjp= NULL;
char *driver= NULL;
char *url= NULL;
char *tabtyp = NULL;
//char *prop= NULL;
char *tabtyp= NULL;
#endif // JDBC_SUPPORT
uint tm, fnc= FNC_NO, supfnc= (FNC_NO | FNC_COL);
bool bif, ok= false, dbf= false;
Expand Down Expand Up @@ -5256,6 +5257,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#if defined(JDBC_SUPPORT)
driver= GetListOption(g, "Driver", topt->oplist, NULL);
// url= GetListOption(g, "URL", topt->oplist, NULL);
// prop = GetListOption(g, "Properties", topt->oplist, NULL);
tabtyp = GetListOption(g, "Tabtype", topt->oplist, NULL);
#endif // JDBC_SUPPORT
mxe= atoi(GetListOption(g,"maxerr", topt->oplist, "0"));
Expand Down Expand Up @@ -5366,6 +5368,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
jdef->SetName(create_info->alias);
sjp= (PJPARM)PlugSubAlloc(g, NULL, sizeof(JDBCPARM));
sjp->Driver= driver;
// sjp->Properties = prop;
sjp->Fsize= 0;
sjp->Scrollable= false;

Expand Down
1 change: 1 addition & 0 deletions storage/connect/jdbccat.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ typedef struct jdbc_parms {
char *Url; // Driver URL
char *User; // User connect info
char *Pwd; // Password connect info
//char *Properties; // Connection property list
//int Cto; // Connect timeout
//int Qto; // Query timeout
int Fsize; // Fetch size
Expand Down
60 changes: 35 additions & 25 deletions storage/connect/jdbconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,10 @@ JDBConn::JDBConn(PGLOBAL g, TDBJDBC *tdbp)
m_Wrap = strcat(strcpy(wn, "wrappers/"), m_Wrap);
} // endif m_Wrap

m_Driver = NULL;
m_Url = NULL;
m_User = NULL;
m_Pwd = NULL;
//m_Driver = NULL;
//m_Url = NULL;
//m_User = NULL;
//m_Pwd = NULL;
m_Ncol = 0;
m_Aff = 0;
m_Rows = 0;
Expand Down Expand Up @@ -772,7 +772,7 @@ bool JDBConn::GetJVM(PGLOBAL g)
/***********************************************************************/
int JDBConn::Open(PJPARM sop)
{

int irc = RC_FX;
bool err = false;
jboolean jt = (trace > 0);
PGLOBAL& g = m_G;
Expand Down Expand Up @@ -865,30 +865,37 @@ int JDBConn::Open(PJPARM sop)
switch (rc) {
case JNI_OK:
strcpy(g->Message, "VM successfully created");
irc = RC_OK;
break;
case JNI_ERR:
strcpy(g->Message, "Initialising JVM failed: unknown error");
return RC_FX;
break;
case JNI_EDETACHED:
strcpy(g->Message, "Thread detached from the VM");
return RC_FX;
break;
case JNI_EVERSION:
strcpy(g->Message, "JNI version error");
return RC_FX;
break;
case JNI_ENOMEM:
strcpy(g->Message, "Not enough memory");
return RC_FX;
break;
case JNI_EEXIST:
strcpy(g->Message, "VM already created");
return RC_FX;
break;
case JNI_EINVAL:
strcpy(g->Message, "Invalid arguments");
return RC_FX;
break;
default:
sprintf(g->Message, "Unknown return code %d", rc);
return RC_FX;
sprintf(g->Message, "Unknown return code %d", (int)rc);
break;
} // endswitch rc

if (trace)
htrc("%s\n", g->Message);

if (irc != RC_OK)
return irc;

//=============== Display JVM version ===============
jint ver = env->GetVersion();
printf("JVM Version %d.%d\n", ((ver>>16)&0x0f), (ver&0x0f));
Expand Down Expand Up @@ -978,28 +985,31 @@ int JDBConn::Open(PJPARM sop)
jobjectArray parms = env->NewObjectArray(4, // constructs java array of 4
env->FindClass("java/lang/String"), NULL); // Strings

m_Driver = sop->Driver;
m_Url = sop->Url;
m_User = sop->User;
m_Pwd = sop->Pwd;
//m_Driver = sop->Driver;
//m_Url = sop->Url;
//m_User = sop->User;
//m_Pwd = sop->Pwd;
m_Scrollable = sop->Scrollable;
m_RowsetSize = sop->Fsize;
//m_LoginTimeout = sop->Cto;
//m_QueryTimeout = sop->Qto;
//m_UseCnc = sop->UseCnc;

// change some elements
if (m_Driver)
env->SetObjectArrayElement(parms, 0, env->NewStringUTF(m_Driver));
if (sop->Driver)
env->SetObjectArrayElement(parms, 0, env->NewStringUTF(sop->Driver));

if (sop->Url)
env->SetObjectArrayElement(parms, 1, env->NewStringUTF(sop->Url));

if (m_Url)
env->SetObjectArrayElement(parms, 1, env->NewStringUTF(m_Url));
if (sop->User)
env->SetObjectArrayElement(parms, 2, env->NewStringUTF(sop->User));

if (m_User)
env->SetObjectArrayElement(parms, 2, env->NewStringUTF(m_User));
if (sop->Pwd)
env->SetObjectArrayElement(parms, 3, env->NewStringUTF(sop->Pwd));

if (m_Pwd)
env->SetObjectArrayElement(parms, 3, env->NewStringUTF(m_Pwd));
//if (sop->Properties)
// env->SetObjectArrayElement(parms, 4, env->NewStringUTF(sop->Properties));

// call method
rc = env->CallIntMethod(job, cid, parms, m_RowsetSize, m_Scrollable);
Expand Down
6 changes: 3 additions & 3 deletions storage/connect/jdbconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ class JDBConn : public BLOCK {
char *Msg;
char *m_Wrap;
char m_IDQuoteChar[2];
PSZ m_Driver;
PSZ m_Url;
PSZ m_User;
//PSZ m_Driver;
//PSZ m_Url;
//PSZ m_User;
PSZ m_Pwd;
int m_Ncol;
int m_Aff;
Expand Down
47 changes: 47 additions & 0 deletions storage/connect/jsonudf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5264,3 +5264,50 @@ char *envar(UDF_INIT *initid, UDF_ARGS *args, char *result,
return str;
} // end of envar

/*********************************************************************************/
/* Returns the distinct number of B occurences in A. */
/*********************************************************************************/
my_bool countin_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
if (args->arg_count != 2) {
strcpy(message, "This function must have 2 arguments");
return true;
} else if (args->arg_type[0] != STRING_RESULT) {
strcpy(message, "First argument must be string");
return true;
} else if (args->arg_type[1] != STRING_RESULT) {
strcpy(message, "Second argument is not a string");
return true;
} // endif args

return false;
} // end of countin_init

long long countin(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *is_null, char *)
{
PSZ str1, str2;
char *s;
long long n = 0;
size_t lg;

lg = (size_t)args->lengths[0];
s = str1 = (PSZ)malloc(lg + 1);
memcpy(str1, args->args[0], lg);
str1[lg] = 0;

lg = (size_t)args->lengths[1];
str2 = (PSZ)malloc(lg + 1);
memcpy(str2, args->args[1], lg);
str2[lg] = 0;

while (s = strstr(s, str2)) {
n++;
s += lg;
} // endwhile

free(str1);
free(str2);
return n;
} // end of countin

3 changes: 3 additions & 0 deletions storage/connect/jsonudf.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ extern "C" {

DllExport my_bool envar_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *envar(UDF_EXEC_ARGS);

DllExport my_bool countin_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport long long countin(UDF_EXEC_ARGS);
} // extern "C"


Expand Down
6 changes: 5 additions & 1 deletion storage/connect/mycat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
#include "filamtxt.h"
#include "tabdos.h"
#include "tabfmt.h"
#if defined(VCT_SUPPORT)
#include "tabvct.h"
#endif // VCT_SUPPORT
#include "tabsys.h"
#if defined(__WIN__)
#include "tabmac.h"
Expand Down Expand Up @@ -549,7 +551,9 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
#if defined(XML_SUPPORT)
case TAB_XML: tdp= new(g) XMLDEF; break;
#endif // XML_SUPPORT
case TAB_VEC: tdp= new(g) VCTDEF; break;
#if defined(VCT_SUPPORT)
case TAB_VEC: tdp = new(g)VCTDEF; break;
#endif // VCT_SUPPORT
#if defined(ODBC_SUPPORT)
case TAB_ODBC: tdp= new(g) ODBCDEF; break;
#endif // ODBC_SUPPORT
Expand Down
13 changes: 9 additions & 4 deletions storage/connect/reldef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
#include "tabcol.h"
#include "filamap.h"
#include "filamfix.h"
#if defined(VCT_SUPPORT)
#include "filamvct.h"
#endif // VCT_SUPPORT
#if defined(ZIP_SUPPORT)
#include "filamzip.h"
#endif // ZIP_SUPPORT
Expand Down Expand Up @@ -683,16 +685,19 @@ PTDB OEMDEF::GetTable(PGLOBAL g, MODE mode)
txfp = new(g) MPXFAM(defp);
else
txfp = new(g) FIXFAM(defp);

} else if (rfm == RECFM_VCT) {
assert (Pxdef->GetDefType() == TYPE_AM_VCT);
#if defined(VCT_SUPPORT)
assert(Pxdef->GetDefType() == TYPE_AM_VCT);

if (map)
txfp = new(g) VCMFAM((PVCTDEF)defp);
else
txfp = new(g) VCTFAM((PVCTDEF)defp);

} // endif's
#else // !VCT_SUPPORT
strcpy(g->Message, "VCT no more supported");
return NULL;
#endif // !VCT_SUPPORT
} // endif's

((PTDBDOS)tdbp)->SetTxfp(txfp);
} // endif Txfp
Expand Down
34 changes: 23 additions & 11 deletions storage/connect/tabfmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,9 @@ bool TDBCSV::SkipHeader(PGLOBAL g)
/***********************************************************************/
int TDBCSV::ReadBuffer(PGLOBAL g)
{
char *p1, *p2, *p = NULL;
int i, n, len, rc = Txfp->ReadBuffer(g);
//char *p1, *p2, *p = NULL;
char *p2, *p = NULL;
int i, n, len, rc = Txfp->ReadBuffer(g);
bool bad = false;

if (trace > 1)
Expand All @@ -846,14 +847,23 @@ int TDBCSV::ReadBuffer(PGLOBAL g)
for (i = 0; i < Fields; i++) {
if (!bad) {
if (Qot && *p2 == Qot) { // Quoted field
for (n = 0, p1 = ++p2; (p = strchr(p1, Qot)); p1 = p + 2)
if (*(p + 1) == Qot)
n++; // Doubled internal quotes
else
break; // Final quote
//for (n = 0, p1 = ++p2; (p = strchr(p1, Qot)); p1 = p + 2)
// if (*(p + 1) == Qot)
// n++; // Doubled internal quotes
// else
// break; // Final quote

for (n = 0, p = ++p2; p; p++)
if (*p == Qot || *p == '\\') {
if (*(++p) == Qot)
n++; // Escaped internal quotes
else if (*(p - 1) == Qot)
break; // Final quote
} // endif *p

if (p) {
len = p++ - p2;
//len = p++ - p2;
len = p - p2 - 1;;

// if (Sep != ' ')
// for (; *p == ' '; p++) ; // Skip blanks
Expand All @@ -873,10 +883,12 @@ int TDBCSV::ReadBuffer(PGLOBAL g)
if (n) {
int j, k;

// Suppress the double of internal quotes
// Suppress the escape of internal quotes
for (j = k = 0; j < len; j++, k++) {
if (p2[j] == Qot)
j++; // skip first one
if (p2[j] == Qot || (p2[j] == '\\' && p2[j + 1] == Qot))
j++; // skip escape char
else if (p2[j] == '\\')
p2[k++] = p2[j++]; // avoid \\Qot

p2[k] = p2[j];
} // endfor i, j
Expand Down
4 changes: 4 additions & 0 deletions storage/connect/tabjdbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ bool JDBCDEF::SetParms(PJPARM sjp)
sjp->Url= Url;
sjp->User= Username;
sjp->Pwd= Password;
//sjp->Properties = Prop;
return true;
} // end of SetParms

Expand Down Expand Up @@ -234,6 +235,7 @@ bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
Read_Only = true;

Wrapname = GetStringCatInfo(g, "Wrapper", NULL);
//Prop = GetStringCatInfo(g, "Properties", NULL);
Tabcat = GetStringCatInfo(g, "Qualifier", NULL);
Tabcat = GetStringCatInfo(g, "Catalog", Tabcat);
Tabschema = GetStringCatInfo(g, "Dbname", NULL);
Expand Down Expand Up @@ -337,6 +339,7 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp)
Schema = tdp->Tabschema;
Ops.User = tdp->Username;
Ops.Pwd = tdp->Password;
// Ops.Properties = tdp->Prop;
Catalog = tdp->Tabcat;
Srcdef = tdp->Srcdef;
Qrystr = tdp->Qrystr;
Expand All @@ -356,6 +359,7 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp)
Ops.Url = NULL;
Ops.User = NULL;
Ops.Pwd = NULL;
// Ops.Properties = NULL;
Catalog = NULL;
Srcdef = NULL;
Qrystr = NULL;
Expand Down
Loading

0 comments on commit 5884aa1

Please sign in to comment.