Commit b6135bb5 authored by Olivier Bertrand's avatar Olivier Bertrand

Continue working on MONGO tables

  modified:   storage/connect/tabmgo.cpp
  modified:   storage/connect/tabmgo.h

Add Trc to STRING allowing to test for truncation (ex oom)
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/tabext.cpp
  modified:   storage/connect/tabjdbc.cpp
  modified:   storage/connect/tabmysql.cpp
  modified:   storage/connect/tabmysql.h
  modified:   storage/connect/tabodbc.cpp
  modified:   storage/connect/xobject.cpp
  modified:   storage/connect/xobject.h
parent 36206acc
# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
SET(CONNECT_PLUGIN_STATIC "connect")
SET(CONNECT_PLUGIN_DYNAMIC "connect")
SET(CONNECT_SOURCES
ha_connect.cc connect.cc user_connect.cc mycat.cc
fmdlex.c osutil.c rcmsg.c rcmsg.h
array.cpp blkfil.cpp colblk.cpp csort.cpp
filamap.cpp filamdbf.cpp filamfix.cpp filamgz.cpp filamtxt.cpp filter.cpp
json.cpp jsonudf.cpp maputil.cpp myconn.cpp myutil.cpp plgdbutl.cpp plugutil.cpp
reldef.cpp tabcol.cpp tabdos.cpp tabext.cpp tabfix.cpp tabfmt.cpp tabjson.cpp
table.cpp tabmul.cpp tabmysql.cpp taboccur.cpp tabpivot.cpp tabsys.cpp tabtbl.cpp
tabutil.cpp tabvir.cpp tabxcl.cpp valblk.cpp value.cpp xindex.cpp xobject.cpp
array.h blkfil.h block.h catalog.h checklvl.h colblk.h connect.h csort.h
engmsg.h filamap.h filamdbf.h filamfix.h filamgz.h filamtxt.h
filter.h global.h ha_connect.h inihandl.h json.h jsonudf.h maputil.h msgid.h
mycat.h myconn.h myutil.h os.h osutil.h plgcnx.h plgdbsem.h preparse.h reldef.h
resource.h tabcol.h tabdos.h tabext.h tabfix.h tabfmt.h tabjson.h tabmul.h
tabmysql.h taboccur.h tabpivot.h tabsys.h tabtbl.h tabutil.h tabvir.h tabxcl.h
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 -DGZ_SUPPORT -DPIVOT_SUPPORT )
#
# OS specific C flags, definitions and source files.
#
IF(UNIX)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Bar: -Wfatal-errors removed (does not present in gcc on solaris10)
if(WITH_WARNINGS)
add_definitions(-Wall -Wextra -Wmissing-declarations)
#message(STATUS "CONNECT: GCC: All warnings enabled")
else()
add_definitions(-Wall -Wmissing-declarations)
add_definitions(-Wno-write-strings)
add_definitions(-Wno-unused-variable)
# Bar: -Wno-unused-but-set-variables commented (does not present on sol10)
# add_definitions(-Wno-unused-but-set-variable)
add_definitions(-Wno-unused-value)
add_definitions(-Wno-unused-function)
add_definitions(-Wno-parentheses)
#add_definitions(-Wno-missing-declarations)
# Bar: -Wno-int-to-pointer-cast commended (does not present in gcc on sol10)
# add_definitions(-Wno-int-to-pointer-cast)
# Bar: -Wno-narrowing commented (does not present in gcc on solaris10)
# add_definitions(-Wno-narrowing)
# This switch is for pure C only:
# add_definitions(-Wno-implicit-function-declaration)
# These switches are for C++ only
# add_definitions(-Wno-reorder)
#message(STATUS "CONNECT: GCC: Some warnings disabled")
endif(WITH_WARNINGS)
endif()
add_definitions( -DUNIX -DLINUX -DUBUNTU )
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -fexceptions -fPIC ")
get_property(inc_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
SET(CONNECT_SOURCES ${CONNECT_SOURCES} inihandl.c)
SET(IPHLPAPI_LIBRARY "")
ELSE(NOT UNIX)
SET(CONNECT_SOURCES ${CONNECT_SOURCES}
tabwmi.cpp tabwmi.h tabmac.cpp tabmac.h macutil.cpp macutil.h)
# Add exception handling to the CONNECT project)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
SET(IPHLPAPI_LIBRARY iphlpapi.lib)
ENDIF(UNIX)
#
# VCT: the VEC format might be not supported in future versions
#
OPTION(CONNECT_WITH_VCT "Compile CONNECT storage engine with VCT support" ON)
IF(CONNECT_WITH_VCT)
SET(CONNECT_SOURCES ${CONNECT_SOURCES} filamvct.cpp tabvct.cpp filamvct.h tabvct.h)
add_definitions(-DVCT_SUPPORT)
ENDIF(CONNECT_WITH_VCT)
#
# XML
#
OPTION(CONNECT_WITH_LIBXML2 "Compile CONNECT storage engine with LIBXML2 support" ON)
IF(CONNECT_WITH_LIBXML2)
IF(WIN32)
#
# NOTE: when switching to static linking of libxml2
# make sure to define LIBXML_STATIC.
#
# Adding some typical places to search in
SET(PC_LIBXML_INCLUDE_DIRS
C:/libxml2/include
C:/libxml/include
D:/libxml/include)
SET(PC_LIBXML_LIBRARY_DIRS
C:/libxml2/lib
C:/libxml/lib
D:/libxml/lib)
ENDIF(WIN32)
FIND_PACKAGE(LibXml2)
IF (LIBXML2_FOUND)
INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
SET(XML_LIBRARY ${LIBXML2_LIBRARIES})
SET(CONNECT_SOURCES ${CONNECT_SOURCES} libdoc.cpp libdoc.h)
add_definitions(-DLIBXML2_SUPPORT)
ENDIF(LIBXML2_FOUND)
ENDIF(CONNECT_WITH_LIBXML2)
IF(WIN32)
# /MP option of the Microsoft compiler does not work well with COM #import
string(REPLACE "/MP" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REPLACE "/MP" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
OPTION(CONNECT_WITH_MSXML "Compile CONNECT storage engine with MSXML support" ON)
IF(CONNECT_WITH_MSXML)
add_definitions(-DMSX6 -DDOMDOC_SUPPORT)
message(STATUS "MSXML library version: msxml6")
SET(MSXML_FOUND 1)
SET(CONNECT_SOURCES ${CONNECT_SOURCES} domdoc.cpp domdoc.h)
ENDIF(CONNECT_WITH_MSXML)
ENDIF(WIN32)
IF(LIBXML2_FOUND OR MSXML_FOUND)
SET(CONNECT_SOURCES ${CONNECT_SOURCES}
tabxml.cpp tabxml.h plgxml.cpp plgxml.h)
ENDIF()
#
# MySQL is now included unconditionnally
#
IF(NOT UNIX)
#
# TODO: remove this
# change to use "#include "../../include/mysql.h" in the sources.
INCLUDE_DIRECTORIES("../../include/mysql")
ENDIF(NOT UNIX)
#
# ODBC
#
OPTION(CONNECT_WITH_ODBC "Compile CONNECT storage engine with ODBC support" ON)
IF(CONNECT_WITH_ODBC)
if(UNIX)
# Note, we currently detect unixODBC only on Linux.
# TODO: detect iODBC as well. Simply adding "iodbc" into NAMES in
# find_library does not work on machines with both unixODBC and iODBC
# installed, because it finds headers from unixODBC while libraries
# from iODBC. We could search for 'isql.h' instead of 'sql.h' so
# the library 'libodbc' gets compiled with 'isql.h' and
# the library 'libiodbc' gets compiled with 'sql'h.
# This will also need changes in the sources (e.g. #include <isql.h>).
find_path(ODBC_INCLUDE_DIR sql.h
/usr/include
/usr/include/odbc
/usr/local/include
/usr/local/include/odbc
/usr/local/odbc/include
#"C:/Program Files/ODBC/include"
#"C:/Program Files/Microsoft SDKs/Windows/v7.0A/include"
#"C:/Program Files/Microsoft SDKs/Windows/v6.0a/include"
#"C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/include"
DOC "Specify the directory containing sql.h."
)
find_library(ODBC_LIBRARY
NAMES odbc odbcinst odbc32
PATHS
/usr/lib
/usr/lib/odbc
/usr/local/lib
/usr/local/lib/odbc
/usr/local/odbc/lib
#"C:/Program Files/ODBC/lib"
#"C:/ODBC/lib/debug"
#"C:/Program Files/Microsoft SDKs/Windows/v7.0A/Lib"
#"C:/Program Files/Microsoft SDKs/Windows/v6.0A/Lib"
#"C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Lib"
DOC "Specify the ODBC driver manager library here."
)
mark_as_advanced(ODBC_LIBRARY ODBC_INCLUDE_DIR)
IF(ODBC_INCLUDE_DIR AND ODBC_LIBRARY)
set(CMAKE_REQUIRED_LIBRARIES ${ODBC_LIBRARY})
set(CMAKE_REQUIRED_INCLUDES ${ODBC_INCLUDE_DIR})
CHECK_CXX_SOURCE_COMPILES(
"
#include <stdio.h>
#include <sql.h>
#include <sqlext.h>
typedef long BOOL; /* this fails with iODBC */
int main() {
SQLULEN rowofs= 0; /* this fails on older unixODBC */
SQLExtendedFetch(NULL, 0, 0, &rowofs, NULL);
return 0;
}
" ODBC_OK)
ENDIF()
IF(ODBC_OK)
INCLUDE_DIRECTORIES(${ODBC_INCLUDE_DIR})
add_definitions(-DODBC_SUPPORT)
SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabodbc.cpp odbconn.cpp)
ELSE()
SET(ODBC_LIBRARY "")
ENDIF()
ELSE(NOT UNIX)
add_definitions(-DODBC_SUPPORT)
SET(ODBC_LIBRARY odbc32.lib odbccp32.lib)
SET(CONNECT_SOURCES ${CONNECT_SOURCES}
tabodbc.cpp tabodbc.h odbccat.h odbconn.cpp odbconn.h)
ENDIF(UNIX)
ENDIF(CONNECT_WITH_ODBC)
#
# JDBC
#
IF(APPLE)
OPTION(CONNECT_WITH_JDBC "Compile CONNECT storage engine without JDBC support" OFF)
ELSE()
OPTION(CONNECT_WITH_JDBC "Compile CONNECT storage engine with JDBC support" ON)
ENDIF()
IF(CONNECT_WITH_JDBC)
FIND_PACKAGE(Java 1.6)
FIND_PACKAGE(JNI)
IF (JAVA_FOUND AND JNI_FOUND)
INCLUDE(UseJava)
INCLUDE_DIRECTORIES(${JAVA_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${JAVA_INCLUDE_PATH2})
# SET(JDBC_LIBRARY ${JAVA_JVM_LIBRARY}) will be dynamically linked
SET(CONNECT_SOURCES ${CONNECT_SOURCES}
jdbconn.cpp tabjdbc.cpp jdbconn.h tabjdbc.h jdbccat.h
JdbcInterface.java ApacheInterface.java MariadbInterface.java
MysqlInterface.java OracleInterface.java PostgresqlInterface.java
JavaWrappers.jar)
# TODO: Find how to compile and install the java wrapper classes
# Find required libraries and include directories
SET (JAVA_SOURCES JdbcInterface.java)
add_jar(JdbcInterface ${JAVA_SOURCES})
install_jar(JdbcInterface DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/JavaWrappers.jar
DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
add_definitions(-DJDBC_SUPPORT)
ELSE()
SET(JDBC_LIBRARY "")
ENDIF()
ENDIF(CONNECT_WITH_JDBC)
#
# ZIP
#
OPTION(CONNECT_WITH_ZIP "Compile CONNECT storage engine with ZIP support" ON)
IF(CONNECT_WITH_ZIP)
SET(CONNECT_SOURCES ${CONNECT_SOURCES} filamzip.cpp tabzip.cpp unzip.c ioapi.c zip.c
filamzip.h tabzip.h ioapi.h unzip.h zip.h)
add_definitions(-DZIP_SUPPORT -DNOCRYPT)
ENDIF(CONNECT_WITH_ZIP)
#
# MONGO (CMAKE NOT YET WORKING)
#
OPTION(CONNECT_WITH_MONGO "Compile CONNECT storage engine with MONGO support" ON)
IF(CONNECT_WITH_MONGO)
# IF(WIN32)
# # Adding some typical places to search in
# SET(PC_MONGO_INCLUDE_DIRS
# C:/mongo-c-driver/include
# D:/mongo-c-driver/include)
# SET(PC_MONGO_LIBRARY_DIRS
# C:/mongo-c-driver/lib
# D:/mongo-c-driver/lib)
# ENDIF(WIN32)
FIND_PACKAGE(libmongoc-1.0 1.7 REQUIRED)
IF (MONGO_FOUND)
message ("-- mongoc found version \"${MONGOC_VERSION}\"")
message ("-- mongoc include path \"${MONGOC_INCLUDE_DIRS}\"")
message ("-- mongoc library path \"${MONGOC_LIBRARY_DIRS}\"")
LINK_DIRECTORIES (${MONGOC_LIBRARY_DIRS})
INCLUDE_DIRECTORIES(${MONGO_INCLUDE_DIR})
# SET(MONGO_LIBRARY ${MONGO_LIBRARIES})
SET(CONNECT_SOURCES ${CONNECT_SOURCES} mongofam.cpp mongofam.h)
add_definitions(-DMONGO_SUPPORT)
ENDIF(MONGO_FOUND)
ENDIF(CONNECT_WITH_MONGO)
#
# XMAP
#
OPTION(CONNECT_WITH_XMAP "Compile CONNECT storage engine with index file mapping support" ON)
IF(CONNECT_WITH_XMAP)
add_definitions(-DXMAP)
ENDIF(CONNECT_WITH_XMAP)
#
# Plugin definition
#
MYSQL_ADD_PLUGIN(connect ${CONNECT_SOURCES}
STORAGE_ENGINE
COMPONENT connect-engine
RECOMPILE_FOR_EMBEDDED
# LINK_LIBRARIES ${ZLIB_LIBRARY} ${XML_LIBRARY} ${ICONV_LIBRARY} $(MONGO_LIBRARY)
LINK_LIBRARIES ${ZLIB_LIBRARY} ${XML_LIBRARY} ${ICONV_LIBRARY}
${ODBC_LIBRARY} ${JDBC_LIBRARY} ${IPHLPAPI_LIBRARY})
...@@ -2283,7 +2283,7 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q, ...@@ -2283,7 +2283,7 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q,
const uchar *ptr; const uchar *ptr;
//uint i, rem, len, klen, stlen; //uint i, rem, len, klen, stlen;
uint i, rem, len, stlen; uint i, rem, len, stlen;
bool nq, both, oom= false; bool nq, both, oom;
OPVAL op; OPVAL op;
Field *fp; Field *fp;
const key_range *ranges[2]; const key_range *ranges[2];
...@@ -2311,9 +2311,9 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q, ...@@ -2311,9 +2311,9 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q,
continue; continue;
if (both && i > 0) if (both && i > 0)
oom|= qry->Append(") AND ("); qry->Append(") AND (");
else else
oom|= qry->Append(" WHERE ("); qry->Append(" WHERE (");
// klen= len= ranges[i]->length; // klen= len= ranges[i]->length;
len= ranges[i]->length; len= ranges[i]->length;
...@@ -2326,14 +2326,14 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q, ...@@ -2326,14 +2326,14 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q,
nq= fp->str_needs_quotes(); nq= fp->str_needs_quotes();
if (kpart != kfp->key_part) if (kpart != kfp->key_part)
oom|= qry->Append(" AND "); qry->Append(" AND ");
if (q) { if (q) {
oom|= qry->Append(q); qry->Append(q);
oom|= qry->Append((PSZ)fp->field_name); qry->Append((PSZ)fp->field_name);
oom|= qry->Append(q); qry->Append(q);
} else } else
oom|= qry->Append((PSZ)fp->field_name); qry->Append((PSZ)fp->field_name);
switch (ranges[i]->flag) { switch (ranges[i]->flag) {
case HA_READ_KEY_EXACT: case HA_READ_KEY_EXACT:
...@@ -2358,10 +2358,10 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q, ...@@ -2358,10 +2358,10 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q,
goto err; goto err;
} // endswitch flag } // endswitch flag
oom|= qry->Append((PSZ)GetValStr(op, false)); qry->Append((PSZ)GetValStr(op, false));
if (nq) if (nq)
oom|= qry->Append('\''); qry->Append('\'');
if (kpart->key_part_flag & HA_VAR_LENGTH_PART) { if (kpart->key_part_flag & HA_VAR_LENGTH_PART) {
String varchar; String varchar;
...@@ -2369,17 +2369,17 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q, ...@@ -2369,17 +2369,17 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q,
varchar.set_quick((char*)ptr + HA_KEY_BLOB_LENGTH, varchar.set_quick((char*)ptr + HA_KEY_BLOB_LENGTH,
var_length, &my_charset_bin); var_length, &my_charset_bin);
oom|= qry->Append(varchar.ptr(), varchar.length(), nq); qry->Append(varchar.ptr(), varchar.length(), nq);
} else { } else {
char strbuff[MAX_FIELD_WIDTH]; char strbuff[MAX_FIELD_WIDTH];
String str(strbuff, sizeof(strbuff), kpart->field->charset()), *res; String str(strbuff, sizeof(strbuff), kpart->field->charset()), *res;
res= fp->val_str(&str, ptr); res= fp->val_str(&str, ptr);
oom|= qry->Append(res->ptr(), res->length(), nq); qry->Append(res->ptr(), res->length(), nq);
} // endif flag } // endif flag
if (nq) if (nq)
oom |= qry->Append('\''); qry->Append('\'');
if (stlen >= len) if (stlen >= len)
break; break;
...@@ -2394,7 +2394,9 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q, ...@@ -2394,7 +2394,9 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q,
} // endfor i } // endfor i
if ((oom|= qry->Append(")"))) qry->Append(')');
if ((oom= qry->IsTruncated()))
strcpy(g->Message, "Out of memory"); strcpy(g->Message, "Out of memory");
dbug_tmp_restore_column_map(table->write_set, old_map); dbug_tmp_restore_column_map(table->write_set, old_map);
......
...@@ -287,7 +287,7 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt) ...@@ -287,7 +287,7 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
{ {
char *schmp = NULL, *catp = NULL, buf[NAM_LEN * 3]; char *schmp = NULL, *catp = NULL, buf[NAM_LEN * 3];
int len; int len;
bool oom = false, first = true; bool first = true;
PTABLE tablep = To_Table; PTABLE tablep = To_Table;
PCOL colp; PCOL colp;
...@@ -341,7 +341,7 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt) ...@@ -341,7 +341,7 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
for (colp = Columns; colp; colp = colp->GetNext()) for (colp = Columns; colp; colp = colp->GetNext())
if (!colp->IsSpecial()) { if (!colp->IsSpecial()) {
if (!first) if (!first)
oom |= Query->Append(", "); Query->Append(", ");
else else
first = false; first = false;
...@@ -350,11 +350,11 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt) ...@@ -350,11 +350,11 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
if (Quote) { if (Quote) {
// Put column name between identifier quotes in case in contains blanks // Put column name between identifier quotes in case in contains blanks
oom |= Query->Append(Quote); Query->Append(Quote);
oom |= Query->Append(buf); Query->Append(buf);
oom |= Query->Append(Quote); Query->Append(Quote);
} else } else
oom |= Query->Append(buf); Query->Append(buf);
((PEXTCOL)colp)->SetRank(++Ncol); ((PEXTCOL)colp)->SetRank(++Ncol);
} // endif colp } // endif colp
...@@ -362,13 +362,13 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt) ...@@ -362,13 +362,13 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
} else } else
// !Columns can occur for queries such that sql count(*) from... // !Columns can occur for queries such that sql count(*) from...
// for which we will count the rows from sql * from... // for which we will count the rows from sql * from...
oom |= Query->Append('*'); Query->Append('*');
} else } else
// SQL statement used to retrieve the size of the result // SQL statement used to retrieve the size of the result
oom |= Query->Append("count(*)"); Query->Append("count(*)");
oom |= Query->Append(" FROM "); Query->Append(" FROM ");
if (Catalog && *Catalog) if (Catalog && *Catalog)
catp = Catalog; catp = Catalog;
...@@ -380,17 +380,17 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt) ...@@ -380,17 +380,17 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
schmp = Schema; schmp = Schema;
if (catp) { if (catp) {
oom |= Query->Append(catp); Query->Append(catp);
if (schmp) { if (schmp) {
oom |= Query->Append('.'); Query->Append('.');
oom |= Query->Append(schmp); Query->Append(schmp);
} // endif schmp } // endif schmp
oom |= Query->Append('.'); Query->Append('.');
} else if (schmp) { } else if (schmp) {
oom |= Query->Append(schmp); Query->Append(schmp);
oom |= Query->Append('.'); Query->Append('.');
} // endif schmp } // endif schmp
// Table name can be encoded in UTF-8 // Table name can be encoded in UTF-8
...@@ -398,18 +398,18 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt) ...@@ -398,18 +398,18 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
if (Quote) { if (Quote) {
// Put table name between identifier quotes in case in contains blanks // Put table name between identifier quotes in case in contains blanks
oom |= Query->Append(Quote); Query->Append(Quote);
oom |= Query->Append(buf); Query->Append(buf);
oom |= Query->Append(Quote); Query->Append(Quote);
} else } else
oom |= Query->Append(buf); Query->Append(buf);
len = Query->GetLength(); len = Query->GetLength();
if (To_CondFil) { if (To_CondFil) {
if (Mode == MODE_READ) { if (Mode == MODE_READ) {
oom |= Query->Append(" WHERE "); Query->Append(" WHERE ");
oom |= Query->Append(To_CondFil->Body); Query->Append(To_CondFil->Body);
len = Query->GetLength() + 1; len = Query->GetLength() + 1;
} else } else
len += (strlen(To_CondFil->Body) + 256); len += (strlen(To_CondFil->Body) + 256);
...@@ -417,10 +417,11 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt) ...@@ -417,10 +417,11 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
} else } else
len += ((Mode == MODE_READX) ? 256 : 1); len += ((Mode == MODE_READX) ? 256 : 1);
if (oom || Query->Resize(len)) { if (Query->IsTruncated()) {
strcpy(g->Message, "MakeSQL: Out of memory"); strcpy(g->Message, "MakeSQL: Out of memory");
return true; return true;
} // endif oom } else
Query->Resize(len);
if (trace) if (trace)
htrc("Query=%s\n", Query->GetStr()); htrc("Query=%s\n", Query->GetStr());
......
...@@ -368,7 +368,7 @@ bool TDBJDBC::MakeInsert(PGLOBAL g) ...@@ -368,7 +368,7 @@ bool TDBJDBC::MakeInsert(PGLOBAL g)
char *schmp = NULL, *catp = NULL, buf[NAM_LEN * 3]; char *schmp = NULL, *catp = NULL, buf[NAM_LEN * 3];
int len = 0; int len = 0;
uint pos; uint pos;
bool b = false, oom = false; bool b = false;
PTABLE tablep = To_Table; PTABLE tablep = To_Table;
PCOL colp; PCOL colp;
...@@ -405,32 +405,32 @@ bool TDBJDBC::MakeInsert(PGLOBAL g) ...@@ -405,32 +405,32 @@ bool TDBJDBC::MakeInsert(PGLOBAL g)
Query = new(g)STRING(g, len, "INSERT INTO "); Query = new(g)STRING(g, len, "INSERT INTO ");
if (catp) { if (catp) {
oom |= Query->Append(catp); Query->Append(catp);
if (schmp) { if (schmp) {
oom |= Query->Append('.'); Query->Append('.');
oom |= Query->Append(schmp); Query->Append(schmp);
} // endif schmp } // endif schmp
oom |= Query->Append('.'); Query->Append('.');
} else if (schmp) { } else if (schmp) {
oom |= Query->Append(schmp); Query->Append(schmp);
oom |= Query->Append('.'); Query->Append('.');
} // endif schmp } // endif schmp
if (Quote) { if (Quote) {
// Put table name between identifier quotes in case in contains blanks // Put table name between identifier quotes in case in contains blanks
oom |= Query->Append(Quote); Query->Append(Quote);
oom |= Query->Append(buf); Query->Append(buf);
oom |= Query->Append(Quote); Query->Append(Quote);
} else } else
oom |= Query->Append(buf); Query->Append(buf);
oom |= Query->Append('('); Query->Append('(');
for (colp = Columns; colp; colp = colp->GetNext()) { for (colp = Columns; colp; colp = colp->GetNext()) {
if (b) if (b)
oom |= Query->Append(", "); Query->Append(", ");
else else
b = true; b = true;
...@@ -439,15 +439,15 @@ bool TDBJDBC::MakeInsert(PGLOBAL g) ...@@ -439,15 +439,15 @@ bool TDBJDBC::MakeInsert(PGLOBAL g)
if (Quote) { if (Quote) {
// Put column name between identifier quotes in case in contains blanks // Put column name between identifier quotes in case in contains blanks
oom |= Query->Append(Quote); Query->Append(Quote);
oom |= Query->Append(buf); Query->Append(buf);
oom |= Query->Append(Quote); Query->Append(Quote);
} else } else
oom |= Query->Append(buf); Query->Append(buf);
} // endfor colp } // endfor colp
if ((oom |= Query->Append(") VALUES ("))) { if ((Query->Append(") VALUES ("))) {
strcpy(g->Message, "MakeInsert: Out of memory"); strcpy(g->Message, "MakeInsert: Out of memory");
return true; return true;
} else // in case prepared statement fails } else // in case prepared statement fails
...@@ -455,9 +455,9 @@ bool TDBJDBC::MakeInsert(PGLOBAL g) ...@@ -455,9 +455,9 @@ bool TDBJDBC::MakeInsert(PGLOBAL g)
// Make prepared statement // Make prepared statement
for (int i = 0; i < Nparm; i++) for (int i = 0; i < Nparm; i++)
oom |= Query->Append("?,"); Query->Append("?,");
if (oom) { if (Query->IsTruncated()) {
strcpy(g->Message, "MakeInsert: Out of memory"); strcpy(g->Message, "MakeInsert: Out of memory");
return true; return true;
} else } else
...@@ -864,7 +864,6 @@ int TDBJDBC::WriteDB(PGLOBAL g) ...@@ -864,7 +864,6 @@ int TDBJDBC::WriteDB(PGLOBAL g)
// an insert query for each line to insert // an insert query for each line to insert
uint len = Query->GetLength(); uint len = Query->GetLength();
char buf[64]; char buf[64];
bool oom = false;
// Make the Insert command value list // Make the Insert command value list
for (PCOL colp = Columns; colp; colp = colp->GetNext()) { for (PCOL colp = Columns; colp; colp = colp->GetNext()) {
...@@ -872,28 +871,28 @@ int TDBJDBC::WriteDB(PGLOBAL g) ...@@ -872,28 +871,28 @@ int TDBJDBC::WriteDB(PGLOBAL g)
char *s = colp->GetValue()->GetCharString(buf); char *s = colp->GetValue()->GetCharString(buf);
if (colp->GetResultType() == TYPE_STRING) if (colp->GetResultType() == TYPE_STRING)
oom |= Query->Append_quoted(s); Query->Append_quoted(s);
else if (colp->GetResultType() == TYPE_DATE) { else if (colp->GetResultType() == TYPE_DATE) {
DTVAL *dtv = (DTVAL*)colp->GetValue(); DTVAL *dtv = (DTVAL*)colp->GetValue();
if (dtv->IsFormatted()) if (dtv->IsFormatted())
oom |= Query->Append_quoted(s); Query->Append_quoted(s);
else else
oom |= Query->Append(s); Query->Append(s);
} else } else
oom |= Query->Append(s); Query->Append(s);
} else } else
oom |= Query->Append("NULL"); Query->Append("NULL");
oom |= Query->Append(','); Query->Append(',');
} // endfor colp } // endfor colp
if (unlikely(oom)) { if (unlikely(Query->IsTruncated())) {
strcpy(g->Message, "WriteDB: Out of memory"); strcpy(g->Message, "WriteDB: Out of memory");
return RC_FX; return RC_FX;
} // endif oom } // endif Query
Query->RepLast(')'); Query->RepLast(')');
......
...@@ -586,15 +586,45 @@ PCOL TDBMGO::InsertSpecialColumn(PCOL colp) ...@@ -586,15 +586,45 @@ PCOL TDBMGO::InsertSpecialColumn(PCOL colp)
int TDBMGO::Cardinality(PGLOBAL g) int TDBMGO::Cardinality(PGLOBAL g)
{ {
if (!g) if (!g)
return 0; return 1;
else if (Cardinal < 0) else if (Cardinal < 0)
if (!Init(g)) {
bson_t *query;
const char *jf = NULL;
if (Pipe)
return 10;
else if (Filter)
jf = Filter;
if (jf) {
query = bson_new_from_json((const uint8_t *)jf, -1, &Error);
if (!query) {
htrc("Wrong filter: %s", Error.message);
return 10;
} // endif Query
} else
query = bson_new();
Cardinal = (int)mongoc_collection_count(Collection,
MONGOC_QUERY_NONE, query, 0, 0, NULL, &Error);
if (Cardinal < 0) {
htrc("Collection count: %s", Error.message);
Cardinal = 10; Cardinal = 10;
} // endif Cardinal
bson_destroy(query);
} else
return 10;
return Cardinal; return Cardinal;
} // end of Cardinality } // end of Cardinality
/***********************************************************************/ /***********************************************************************/
/* MONGO GetMaxSize: returns file size estimate in number of lines. */ /* MONGO GetMaxSize: returns collection size estimate. */
/***********************************************************************/ /***********************************************************************/
int TDBMGO::GetMaxSize(PGLOBAL g) int TDBMGO::GetMaxSize(PGLOBAL g)
{ {
...@@ -623,28 +653,64 @@ bool TDBMGO::Init(PGLOBAL g) ...@@ -623,28 +653,64 @@ bool TDBMGO::Init(PGLOBAL g)
} // endif p } // endif p
if (*Options) { } // endif Options
if (trace)
htrc("options=%s\n", Options);
Opts = bson_new_from_json((const uint8_t *)Options, -1, &Error); Uri = mongoc_uri_new(Uristr);
if (!Opts) { if (!Uri) {
sprintf(g->Message, "Wrong options: %s", Error.message); sprintf(g->Message, "Failed to parse URI: \"%s\"", Uristr);
return true; return true;
} // endif Opts } // endif Uri
} // endif *Options // Create a new client pool instance
Pool = mongoc_client_pool_new(Uri);
mongoc_client_pool_set_error_api(Pool, 2);
} // endif Options // Register the application name so we can track it in the profile logs
// on the server. This can also be done from the URI.
mongoc_client_pool_set_appname(Pool, "Connect");
if (Pipe) { // Create a new client instance
Client = mongoc_client_pool_pop(Pool);
//Client = mongoc_client_new(uristr);
if (!Client) {
sprintf(g->Message, "Failed to get Client");
return true;
} // endif Client
//mongoc_client_set_error_api(Client, 2);
// Register the application name so we can track it in the profile logs
// on the server. This can also be done from the URI.
//mongoc_client_set_appname(Client, "Connect");
// Get a handle on the database Db_name and collection Coll_name
// Database = mongoc_client_get_database(Client, Db_name);
// Collection = mongoc_database_get_collection(Database, Coll_name);
Collection = mongoc_client_get_collection(Client, Db_name, Coll_name);
if (!Collection) {
sprintf(g->Message, "Failed to get Collection %s.%s", Db_name, Coll_name);
return true;
} // endif Collection
Done = true;
return false;
} // end of Init
/***********************************************************************/
/* OpenDB: Data Base open routine for MONGO access method. */
/***********************************************************************/
bool TDBMGO::MakeCursor(PGLOBAL g)
{
const char *p; const char *p;
PSTRG s;
if (Pipe) {
if (trace) if (trace)
htrc("Pipeline: %s\n", Options); htrc("Pipeline: %s\n", Options);
if (To_Filter) {
p = strrchr(Options, ']'); p = strrchr(Options, ']');
if (!p) { if (!p) {
...@@ -653,25 +719,36 @@ bool TDBMGO::Init(PGLOBAL g) ...@@ -653,25 +719,36 @@ bool TDBMGO::Init(PGLOBAL g)
} else } else
*(char*)p = 0; *(char*)p = 0;
PSTRG s = new(g) STRING(g, 1023, (PSZ)Options); s = new(g) STRING(g, 1023, (PSZ)Options);
if (To_Filter) {
s->Append(",{\"$match\":"); s->Append(",{\"$match\":");
if (To_Filter->MakeSelector(g, s)) { if (To_Filter->MakeSelector(g, s)) {
strcpy(g->Message, "Failed making selector"); strcpy(g->Message, "Failed making selector");
return true; return true;
} // endif Selector } else
s->Append('}');
To_Filter = NULL; // Not needed anymore
} // endif To_Filter
s->Append("}]}"); // Project list
s->Append(",{\"$project\":{\"_id\":0");
for (PCOL cp = Columns; cp; cp = cp->GetNext()) {
s->Append(",\"");
s->Append(((PMGOCOL)cp)->Jpath);
s->Append("\":1");
} // endfor cp
s->Append("}}]}");
s->Resize(s->GetLength() + 1); s->Resize(s->GetLength() + 1);
p = s->GetStr(); p = s->GetStr();
if (trace) if (trace)
htrc("New Pipeline: %s\n", p); htrc("New Pipeline: %s\n", p);
To_Filter = NULL; // Not needed anymore
} else
p = Options;
Query = bson_new_from_json((const uint8_t *)p, -1, &Error); Query = bson_new_from_json((const uint8_t *)p, -1, &Error);
if (!Query) { if (!Query) {
...@@ -679,7 +756,16 @@ bool TDBMGO::Init(PGLOBAL g) ...@@ -679,7 +756,16 @@ bool TDBMGO::Init(PGLOBAL g)
return true; return true;
} // endif Query } // endif Query
} else if (Filter || To_Filter) { Cursor = mongoc_collection_aggregate(Collection, MONGOC_QUERY_NONE,
Query, NULL, NULL);
if (mongoc_cursor_error(Cursor, &Error)) {
sprintf(g->Message, "Mongo aggregate Failure: %s", Error.message);
return true;
} // endif cursor
} else {
if (Filter || To_Filter) {
if (trace) { if (trace) {
if (Filter) if (Filter)
htrc("Filter: %s\n", Filter); htrc("Filter: %s\n", Filter);
...@@ -693,7 +779,7 @@ bool TDBMGO::Init(PGLOBAL g) ...@@ -693,7 +779,7 @@ bool TDBMGO::Init(PGLOBAL g)
} // endif trace } // endif trace
PSTRG s = new(g) STRING(g, 1023, (PSZ)Filter); s = new(g) STRING(g, 1023, (PSZ)Filter);
if (To_Filter) { if (To_Filter) {
if (Filter) if (Filter)
...@@ -704,13 +790,13 @@ bool TDBMGO::Init(PGLOBAL g) ...@@ -704,13 +790,13 @@ bool TDBMGO::Init(PGLOBAL g)
return true; return true;
} // endif Selector } // endif Selector
s->Resize(s->GetLength() + 1);
To_Filter = NULL; // Not needed anymore To_Filter = NULL; // Not needed anymore
} // endif To_Filter } // endif To_Filter
if (trace) if (trace)
htrc("selector: %s\n", s->GetStr()); htrc("selector: %s\n", s->GetStr());
s->Resize(s->GetLength() + 1);
Query = bson_new_from_json((const uint8_t *)s->GetStr(), -1, &Error); Query = bson_new_from_json((const uint8_t *)s->GetStr(), -1, &Error);
if (!Query) { if (!Query) {
...@@ -721,49 +807,39 @@ bool TDBMGO::Init(PGLOBAL g) ...@@ -721,49 +807,39 @@ bool TDBMGO::Init(PGLOBAL g)
} else } else
Query = bson_new(); Query = bson_new();
Uri = mongoc_uri_new(Uristr); if (Options && *Options) {
if (trace)
if (!Uri) { htrc("options=%s\n", Options);
sprintf(g->Message, "Failed to parse URI: \"%s\"", Uristr);
return true;
} // endif Uri
// Create a new client pool instance Opts = bson_new_from_json((const uint8_t *)Options, -1, &Error);
Pool = mongoc_client_pool_new(Uri); } else {
mongoc_client_pool_set_error_api(Pool, 2); // Projection list
if (s)
s->Set("{\"projection\":{\"_id\":0");
else
s = new(g) STRING(g, 511, "{\"projection\":{\"_id\":0");
// Register the application name so we can track it in the profile logs for (PCOL cp = Columns; cp; cp = cp->GetNext()) {
// on the server. This can also be done from the URI. s->Append(",\"");
mongoc_client_pool_set_appname(Pool, "Connect"); s->Append(((PMGOCOL)cp)->Jpath);
s->Append("\":1");
} // endfor cp
// Create a new client instance s->Append("}}");
Client = mongoc_client_pool_pop(Pool); s->Resize(s->GetLength() + 1);
//Client = mongoc_client_new(uristr); Opts = bson_new_from_json((const uint8_t *)s->GetStr(), -1, &Error);
} // endif Options
if (!Client) { if (!Opts) {
sprintf(g->Message, "Failed to get Client"); sprintf(g->Message, "Wrong options: %s", Error.message);
return true; return true;
} // endif Client } // endif Opts
//mongoc_client_set_error_api(Client, 2);
// Register the application name so we can track it in the profile logs
// on the server. This can also be done from the URI.
//mongoc_client_set_appname(Client, "Connect");
// Get a handle on the database Db_name and collection Coll_name
// Database = mongoc_client_get_database(Client, Db_name);
// Collection = mongoc_database_get_collection(Database, Coll_name);
Collection = mongoc_client_get_collection(Client, Db_name, Coll_name);
if (!Collection) { Cursor = mongoc_collection_find_with_opts(Collection, Query, Opts, NULL);
sprintf(g->Message, "Failed to get Collection %s.%s", Db_name, Coll_name); } // endif Pipe
return true;
} // endif Collection
Done = true;
return false; return false;
} // end of Init } // end of MakeCursor
/***********************************************************************/ /***********************************************************************/
/* OpenDB: Data Base open routine for MONGO access method. */ /* OpenDB: Data Base open routine for MONGO access method. */
...@@ -797,17 +873,8 @@ bool TDBMGO::OpenDB(PGLOBAL g) ...@@ -797,17 +873,8 @@ bool TDBMGO::OpenDB(PGLOBAL g)
} else if (Mode == MODE_INSERT) } else if (Mode == MODE_INSERT)
MakeColumnGroups(g); MakeColumnGroups(g);
else if (Pipe) { else if (MakeCursor(g))
Cursor = mongoc_collection_aggregate(Collection, MONGOC_QUERY_NONE,
Query, NULL, NULL);
if (mongoc_cursor_error(Cursor, &Error)) {
sprintf(g->Message, "Mongo aggregate Failure: %s", Error.message);
return true; return true;
} // endif cursor
} else
Cursor = mongoc_collection_find_with_opts(Collection, Query, Opts, NULL);
} // endif Use } // endif Use
......
...@@ -124,8 +124,8 @@ class DllExport TDBMGO : public TDBEXT { ...@@ -124,8 +124,8 @@ class DllExport TDBMGO : public TDBEXT {
TDBMGO(TDBMGO *tdbp); TDBMGO(TDBMGO *tdbp);
// Implementation // Implementation
virtual AMT GetAmType(void) { return TYPE_AM_MGO; } virtual AMT GetAmType(void) {return TYPE_AM_MGO;}
virtual PTDB Duplicate(PGLOBAL g) { return (PTDB)new(g) TDBMGO(this); } virtual PTDB Duplicate(PGLOBAL g) {return (PTDB)new(g) TDBMGO(this);}
// Methods // Methods
virtual PTDB Clone(PTABS t); virtual PTDB Clone(PTABS t);
...@@ -145,6 +145,7 @@ class DllExport TDBMGO : public TDBEXT { ...@@ -145,6 +145,7 @@ class DllExport TDBMGO : public TDBEXT {
protected: protected:
bool Init(PGLOBAL g); bool Init(PGLOBAL g);
bool MakeCursor(PGLOBAL g);
void ShowDocument(bson_iter_t *i, const bson_t *b, const char *k); void ShowDocument(bson_iter_t *i, const bson_t *b, const char *k);
void MakeColumnGroups(PGLOBAL g); void MakeColumnGroups(PGLOBAL g);
bool DocWrite(PGLOBAL g, PINCOL icp); bool DocWrite(PGLOBAL g, PINCOL icp);
......
...@@ -495,11 +495,11 @@ PCOL TDBMYSQL::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) ...@@ -495,11 +495,11 @@ PCOL TDBMYSQL::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n)
/* filter should be removed from column list. */ /* filter should be removed from column list. */
/***********************************************************************/ /***********************************************************************/
bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx) bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx)
{ {
//char *tk = "`"; //char *tk = "`";
char tk = '`'; char tk = '`';
int len = 0, rank = 0; int len = 0, rank = 0;
bool b = false, oom = false; bool b = false;
PCOL colp; PCOL colp;
//PDBUSER dup = PlgGetUser(g); //PDBUSER dup = PlgGetUser(g);
...@@ -526,13 +526,13 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx) ...@@ -526,13 +526,13 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx)
for (colp = Columns; colp; colp = colp->GetNext()) for (colp = Columns; colp; colp = colp->GetNext())
if (!colp->IsSpecial()) { if (!colp->IsSpecial()) {
if (b) if (b)
oom |= Query->Append(", "); Query->Append(", ");
else else
b = true; b = true;
oom |= Query->Append(tk); Query->Append(tk);
oom |= Query->Append(colp->GetName()); Query->Append(colp->GetName());
oom |= Query->Append(tk); Query->Append(tk);
((PMYCOL)colp)->Rank = rank++; ((PMYCOL)colp)->Rank = rank++;
} // endif colp } // endif colp
...@@ -542,22 +542,22 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx) ...@@ -542,22 +542,22 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx)
// Query '*' from... // Query '*' from...
// (the use of a char constant minimize the result storage) // (the use of a char constant minimize the result storage)
if (Isview) if (Isview)
oom |= Query->Append('*'); Query->Append('*');
else else
oom |= Query->Append("'*'"); Query->Append("'*'");
} // endif ncol } // endif ncol
oom |= Query->Append(" FROM "); Query->Append(" FROM ");
oom |= Query->Append(tk); Query->Append(tk);
oom |= Query->Append(TableName); Query->Append(TableName);
oom |= Query->Append(tk); Query->Append(tk);
len = Query->GetLength(); len = Query->GetLength();
if (To_CondFil) { if (To_CondFil) {
if (!mx) { if (!mx) {
oom |= Query->Append(" WHERE "); Query->Append(" WHERE ");
oom |= Query->Append(To_CondFil->Body); Query->Append(To_CondFil->Body);
len = Query->GetLength() + 1; len = Query->GetLength() + 1;
} else } else
len += (strlen(To_CondFil->Body) + 256); len += (strlen(To_CondFil->Body) + 256);
...@@ -565,16 +565,16 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx) ...@@ -565,16 +565,16 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx)
} else } else
len += (mx ? 256 : 1); len += (mx ? 256 : 1);
if (oom || Query->Resize(len)) { if (Query->IsTruncated() || Query->Resize(len)) {
strcpy(g->Message, "MakeSelect: Out of memory"); strcpy(g->Message, "MakeSelect: Out of memory");
return true; return true;
} // endif oom } // endif Query
if (trace) if (trace)
htrc("Query=%s\n", Query->GetStr()); htrc("Query=%s\n", Query->GetStr());
return false; return false;
} // end of MakeSelect } // end of MakeSelect
/***********************************************************************/ /***********************************************************************/
/* MakeInsert: make the Insert statement used with MySQL connection. */ /* MakeInsert: make the Insert statement used with MySQL connection. */
...@@ -583,7 +583,7 @@ bool TDBMYSQL::MakeInsert(PGLOBAL g) ...@@ -583,7 +583,7 @@ bool TDBMYSQL::MakeInsert(PGLOBAL g)
{ {
char *tk = "`"; char *tk = "`";
uint len = 0; uint len = 0;
bool b = false, oom; bool oom, b = false;
PCOL colp; PCOL colp;
if (Query) if (Query)
...@@ -622,38 +622,38 @@ bool TDBMYSQL::MakeInsert(PGLOBAL g) ...@@ -622,38 +622,38 @@ bool TDBMYSQL::MakeInsert(PGLOBAL g)
Query = new(g) STRING(g, len); Query = new(g) STRING(g, len);
if (Delayed) if (Delayed)
oom = Query->Set("INSERT DELAYED INTO "); Query->Set("INSERT DELAYED INTO ");
else else
oom = Query->Set("INSERT INTO "); Query->Set("INSERT INTO ");
oom |= Query->Append(tk); Query->Append(tk);
oom |= Query->Append(TableName); Query->Append(TableName);
oom |= Query->Append("` ("); Query->Append("` (");
for (colp = Columns; colp; colp = colp->GetNext()) { for (colp = Columns; colp; colp = colp->GetNext()) {
if (b) if (b)
oom |= Query->Append(", "); Query->Append(", ");
else else
b = true; b = true;
oom |= Query->Append(tk); Query->Append(tk);
oom |= Query->Append(colp->GetName()); Query->Append(colp->GetName());
oom |= Query->Append(tk); Query->Append(tk);
} // endfor colp } // endfor colp
oom |= Query->Append(") VALUES ("); Query->Append(") VALUES (");
#if defined(MYSQL_PREPARED_STATEMENTS) #if defined(MYSQL_PREPARED_STATEMENTS)
if (Prep) { if (Prep) {
for (int i = 0; i < Nparm; i++) for (int i = 0; i < Nparm; i++)
oom |= Query->Append("?,"); Query->Append("?,");
Query->RepLast(')'); Query->RepLast(')');
Query->Trim(); Query->Trim();
} // endif Prep } // endif Prep
#endif // MYSQL_PREPARED_STATEMENTS #endif // MYSQL_PREPARED_STATEMENTS
if (oom) if ((oom = Query->IsTruncated()))
strcpy(g->Message, "MakeInsert: Out of memory"); strcpy(g->Message, "MakeInsert: Out of memory");
return oom; return oom;
...@@ -684,18 +684,18 @@ bool TDBMYSQL::MakeCommand(PGLOBAL g) ...@@ -684,18 +684,18 @@ bool TDBMYSQL::MakeCommand(PGLOBAL g)
strlwr(strcpy(name, Name)); // Not a keyword strlwr(strcpy(name, Name)); // Not a keyword
if ((p = strstr(qrystr, name))) { if ((p = strstr(qrystr, name))) {
bool oom = Query->Set(Qrystr, p - qrystr); Query->Set(Qrystr, p - qrystr);
if (qtd && *(p-1) == ' ') { if (qtd && *(p-1) == ' ') {
oom |= Query->Append('`'); Query->Append('`');
oom |= Query->Append(TableName); Query->Append(TableName);
oom |= Query->Append('`'); Query->Append('`');
} else } else
oom |= Query->Append(TableName); Query->Append(TableName);
oom |= Query->Append(Qrystr + (p - qrystr) + strlen(name)); Query->Append(Qrystr + (p - qrystr) + strlen(name));
if (oom) { if (Query->IsTruncated()) {
strcpy(g->Message, "MakeCommand: Out of memory"); strcpy(g->Message, "MakeCommand: Out of memory");
return true; return true;
} else } else
...@@ -1161,24 +1161,23 @@ int TDBMYSQL::WriteDB(PGLOBAL g) ...@@ -1161,24 +1161,23 @@ int TDBMYSQL::WriteDB(PGLOBAL g)
int rc; int rc;
uint len = Query->GetLength(); uint len = Query->GetLength();
char buf[64]; char buf[64];
bool oom = false;
// Make the Insert command value list // Make the Insert command value list
for (PCOL colp = Columns; colp; colp = colp->GetNext()) { for (PCOL colp = Columns; colp; colp = colp->GetNext()) {
if (!colp->GetValue()->IsNull()) { if (!colp->GetValue()->IsNull()) {
if (colp->GetResultType() == TYPE_STRING || if (colp->GetResultType() == TYPE_STRING ||
colp->GetResultType() == TYPE_DATE) colp->GetResultType() == TYPE_DATE)
oom |= Query->Append_quoted(colp->GetValue()->GetCharString(buf)); Query->Append_quoted(colp->GetValue()->GetCharString(buf));
else else
oom |= Query->Append(colp->GetValue()->GetCharString(buf)); Query->Append(colp->GetValue()->GetCharString(buf));
} else } else
oom |= Query->Append("NULL"); Query->Append("NULL");
oom |= Query->Append(','); Query->Append(',');
} // endfor colp } // endfor colp
if (unlikely(oom)) { if (unlikely(Query->IsTruncated())) {
strcpy(g->Message, "WriteDB: Out of memory"); strcpy(g->Message, "WriteDB: Out of memory");
rc = RC_FX; rc = RC_FX;
} else { } else {
...@@ -1186,7 +1185,7 @@ int TDBMYSQL::WriteDB(PGLOBAL g) ...@@ -1186,7 +1185,7 @@ int TDBMYSQL::WriteDB(PGLOBAL g)
Myc.m_Rows = -1; // To execute the query Myc.m_Rows = -1; // To execute the query
rc = Myc.ExecSQL(g, Query->GetStr()); rc = Myc.ExecSQL(g, Query->GetStr());
Query->Truncate(len); // Restore query Query->Truncate(len); // Restore query
} // endif oom } // endif Query
return (rc == RC_NF) ? RC_OK : rc; // RC_NF is Ok return (rc == RC_NF) ? RC_OK : rc; // RC_NF is Ok
} // end of WriteDB } // end of WriteDB
......
...@@ -109,7 +109,7 @@ class TDBMYSQL : public TDBEXT { ...@@ -109,7 +109,7 @@ class TDBMYSQL : public TDBEXT {
// Internal functions // Internal functions
bool MakeSelect(PGLOBAL g, bool mx); bool MakeSelect(PGLOBAL g, bool mx);
bool MakeInsert(PGLOBAL g); bool MakeInsert(PGLOBAL g);
int BindColumns(PGLOBAL g); int BindColumns(PGLOBAL g __attribute__((unused)));
virtual bool MakeCommand(PGLOBAL g); virtual bool MakeCommand(PGLOBAL g);
//int MakeUpdate(PGLOBAL g); //int MakeUpdate(PGLOBAL g);
//int MakeDelete(PGLOBAL g); //int MakeDelete(PGLOBAL g);
......
...@@ -299,7 +299,7 @@ bool TDBODBC::MakeInsert(PGLOBAL g) ...@@ -299,7 +299,7 @@ bool TDBODBC::MakeInsert(PGLOBAL g)
{ {
char *schmp = NULL, *catp = NULL, buf[NAM_LEN * 3]; char *schmp = NULL, *catp = NULL, buf[NAM_LEN * 3];
int len = 0; int len = 0;
bool b = false, oom = false; bool oom, b = false;
PTABLE tablep = To_Table; PTABLE tablep = To_Table;
PCOL colp; PCOL colp;
...@@ -336,32 +336,32 @@ bool TDBODBC::MakeInsert(PGLOBAL g) ...@@ -336,32 +336,32 @@ bool TDBODBC::MakeInsert(PGLOBAL g)
Query = new(g) STRING(g, len, "INSERT INTO "); Query = new(g) STRING(g, len, "INSERT INTO ");
if (catp) { if (catp) {
oom |= Query->Append(catp); Query->Append(catp);
if (schmp) { if (schmp) {
oom |= Query->Append('.'); Query->Append('.');
oom |= Query->Append(schmp); Query->Append(schmp);
} // endif schmp } // endif schmp
oom |= Query->Append('.'); Query->Append('.');
} else if (schmp) { } else if (schmp) {
oom |= Query->Append(schmp); Query->Append(schmp);
oom |= Query->Append('.'); Query->Append('.');
} // endif schmp } // endif schmp
if (Quote) { if (Quote) {
// Put table name between identifier quotes in case in contains blanks // Put table name between identifier quotes in case in contains blanks
oom |= Query->Append(Quote); Query->Append(Quote);
oom |= Query->Append(buf); Query->Append(buf);
oom |= Query->Append(Quote); Query->Append(Quote);
} else } else
oom |= Query->Append(buf); Query->Append(buf);
oom |= Query->Append('('); Query->Append('(');
for (colp = Columns; colp; colp = colp->GetNext()) { for (colp = Columns; colp; colp = colp->GetNext()) {
if (b) if (b)
oom |= Query->Append(", "); Query->Append(", ");
else else
b = true; b = true;
...@@ -370,20 +370,20 @@ bool TDBODBC::MakeInsert(PGLOBAL g) ...@@ -370,20 +370,20 @@ bool TDBODBC::MakeInsert(PGLOBAL g)
if (Quote) { if (Quote) {
// Put column name between identifier quotes in case in contains blanks // Put column name between identifier quotes in case in contains blanks
oom |= Query->Append(Quote); Query->Append(Quote);
oom |= Query->Append(buf); Query->Append(buf);
oom |= Query->Append(Quote); Query->Append(Quote);
} else } else
oom |= Query->Append(buf); Query->Append(buf);
} // endfor colp } // endfor colp
oom |= Query->Append(") VALUES ("); Query->Append(") VALUES (");
for (int i = 0; i < Nparm; i++) for (int i = 0; i < Nparm; i++)
oom |= Query->Append("?,"); Query->Append("?,");
if (oom) if ((oom = Query->IsTruncated()))
strcpy(g->Message, "MakeInsert: Out of memory"); strcpy(g->Message, "MakeInsert: Out of memory");
else else
Query->RepLast(')'); Query->RepLast(')');
......
...@@ -192,7 +192,7 @@ void CONSTANT::Print(PGLOBAL g, char *ps, uint z) ...@@ -192,7 +192,7 @@ void CONSTANT::Print(PGLOBAL g, char *ps, uint z)
/* STRING public constructor for new char values. Alloc Size must be */ /* STRING public constructor for new char values. Alloc Size must be */
/* calculated because PlugSubAlloc rounds up size to multiple of 8. */ /* calculated because PlugSubAlloc rounds up size to multiple of 8. */
/***********************************************************************/ /***********************************************************************/
STRING::STRING(PGLOBAL g, uint n, char *str) STRING::STRING(PGLOBAL g, uint n, PSZ str)
{ {
G = g; G = g;
Length = (str) ? strlen(str) : 0; Length = (str) ? strlen(str) : 0;
...@@ -205,10 +205,12 @@ STRING::STRING(PGLOBAL g, uint n, char *str) ...@@ -205,10 +205,12 @@ STRING::STRING(PGLOBAL g, uint n, char *str)
Next = GetNext(); Next = GetNext();
Size = Next - Strp; Size = Next - Strp;
Trc = false;
} else { } else {
// This should normally never happen // This should normally never happen
Next = NULL; Next = NULL;
Size = 0; Size = 0;
Trc = true;
} // endif Strp } // endif Strp
} // end of STRING constructor } // end of STRING constructor
...@@ -229,6 +231,7 @@ char *STRING::Realloc(uint len) ...@@ -229,6 +231,7 @@ char *STRING::Realloc(uint len)
if (!p) { if (!p) {
// No more room in Sarea; this is very unlikely // No more room in Sarea; this is very unlikely
strcpy(G->Message, "No more room in work area"); strcpy(G->Message, "No more room in work area");
Trc = true;
return NULL; return NULL;
} // endif p } // endif p
......
...@@ -130,6 +130,7 @@ class DllExport STRING : public BLOCK { ...@@ -130,6 +130,7 @@ class DllExport STRING : public BLOCK {
inline void SetLength(uint n) {Length = n;} inline void SetLength(uint n) {Length = n;}
inline PSZ GetStr(void) {return Strp;} inline PSZ GetStr(void) {return Strp;}
inline uint32 GetSize(void) {return Size;} inline uint32 GetSize(void) {return Size;}
inline bool IsTruncated(void) {return Trc;}
// Methods // Methods
inline void Reset(void) {*Strp = 0;} inline void Reset(void) {*Strp = 0;}
...@@ -156,6 +157,7 @@ class DllExport STRING : public BLOCK { ...@@ -156,6 +157,7 @@ class DllExport STRING : public BLOCK {
PSZ Strp; // The char string PSZ Strp; // The char string
uint Length; // String length uint Length; // String length
uint Size; // Allocated size uint Size; // Allocated size
bool Trc; // When truncated
char *Next; // Next alloc position char *Next; // Next alloc position
}; // end of class STRING }; // end of class STRING
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment