1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00

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
This commit is contained in:
Olivier Bertrand
2017-04-26 18:38:32 +02:00
parent 36206acc2f
commit b6135bb51e
11 changed files with 679 additions and 260 deletions

View File

@@ -0,0 +1,345 @@
# 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})

View File

@@ -2283,7 +2283,7 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q,
const uchar *ptr;
//uint i, rem, len, klen, stlen;
uint i, rem, len, stlen;
bool nq, both, oom= false;
bool nq, both, oom;
OPVAL op;
Field *fp;
const key_range *ranges[2];
@@ -2311,9 +2311,9 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q,
continue;
if (both && i > 0)
oom|= qry->Append(") AND (");
qry->Append(") AND (");
else
oom|= qry->Append(" WHERE (");
qry->Append(" WHERE (");
// klen= len= ranges[i]->length;
len= ranges[i]->length;
@@ -2326,14 +2326,14 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q,
nq= fp->str_needs_quotes();
if (kpart != kfp->key_part)
oom|= qry->Append(" AND ");
qry->Append(" AND ");
if (q) {
oom|= qry->Append(q);
oom|= qry->Append((PSZ)fp->field_name);
oom|= qry->Append(q);
qry->Append(q);
qry->Append((PSZ)fp->field_name);
qry->Append(q);
} else
oom|= qry->Append((PSZ)fp->field_name);
qry->Append((PSZ)fp->field_name);
switch (ranges[i]->flag) {
case HA_READ_KEY_EXACT:
@@ -2358,10 +2358,10 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q,
goto err;
} // endswitch flag
oom|= qry->Append((PSZ)GetValStr(op, false));
qry->Append((PSZ)GetValStr(op, false));
if (nq)
oom|= qry->Append('\'');
qry->Append('\'');
if (kpart->key_part_flag & HA_VAR_LENGTH_PART) {
String varchar;
@@ -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,
var_length, &my_charset_bin);
oom|= qry->Append(varchar.ptr(), varchar.length(), nq);
qry->Append(varchar.ptr(), varchar.length(), nq);
} else {
char strbuff[MAX_FIELD_WIDTH];
String str(strbuff, sizeof(strbuff), kpart->field->charset()), *res;
res= fp->val_str(&str, ptr);
oom|= qry->Append(res->ptr(), res->length(), nq);
qry->Append(res->ptr(), res->length(), nq);
} // endif flag
if (nq)
oom |= qry->Append('\'');
qry->Append('\'');
if (stlen >= len)
break;
@@ -2394,7 +2394,9 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q,
} // endfor i
if ((oom|= qry->Append(")")))
qry->Append(')');
if ((oom= qry->IsTruncated()))
strcpy(g->Message, "Out of memory");
dbug_tmp_restore_column_map(table->write_set, old_map);

View File

@@ -287,7 +287,7 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
{
char *schmp = NULL, *catp = NULL, buf[NAM_LEN * 3];
int len;
bool oom = false, first = true;
bool first = true;
PTABLE tablep = To_Table;
PCOL colp;
@@ -341,7 +341,7 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
for (colp = Columns; colp; colp = colp->GetNext())
if (!colp->IsSpecial()) {
if (!first)
oom |= Query->Append(", ");
Query->Append(", ");
else
first = false;
@@ -350,11 +350,11 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
if (Quote) {
// Put column name between identifier quotes in case in contains blanks
oom |= Query->Append(Quote);
oom |= Query->Append(buf);
oom |= Query->Append(Quote);
Query->Append(Quote);
Query->Append(buf);
Query->Append(Quote);
} else
oom |= Query->Append(buf);
Query->Append(buf);
((PEXTCOL)colp)->SetRank(++Ncol);
} // endif colp
@@ -362,13 +362,13 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
} else
// !Columns can occur for queries such that sql count(*) from...
// for which we will count the rows from sql * from...
oom |= Query->Append('*');
Query->Append('*');
} else
// 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)
catp = Catalog;
@@ -380,17 +380,17 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
schmp = Schema;
if (catp) {
oom |= Query->Append(catp);
Query->Append(catp);
if (schmp) {
oom |= Query->Append('.');
oom |= Query->Append(schmp);
Query->Append('.');
Query->Append(schmp);
} // endif schmp
oom |= Query->Append('.');
Query->Append('.');
} else if (schmp) {
oom |= Query->Append(schmp);
oom |= Query->Append('.');
Query->Append(schmp);
Query->Append('.');
} // endif schmp
// Table name can be encoded in UTF-8
@@ -398,18 +398,18 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
if (Quote) {
// Put table name between identifier quotes in case in contains blanks
oom |= Query->Append(Quote);
oom |= Query->Append(buf);
oom |= Query->Append(Quote);
Query->Append(Quote);
Query->Append(buf);
Query->Append(Quote);
} else
oom |= Query->Append(buf);
Query->Append(buf);
len = Query->GetLength();
if (To_CondFil) {
if (Mode == MODE_READ) {
oom |= Query->Append(" WHERE ");
oom |= Query->Append(To_CondFil->Body);
Query->Append(" WHERE ");
Query->Append(To_CondFil->Body);
len = Query->GetLength() + 1;
} else
len += (strlen(To_CondFil->Body) + 256);
@@ -417,10 +417,11 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
} else
len += ((Mode == MODE_READX) ? 256 : 1);
if (oom || Query->Resize(len)) {
if (Query->IsTruncated()) {
strcpy(g->Message, "MakeSQL: Out of memory");
return true;
} // endif oom
} else
Query->Resize(len);
if (trace)
htrc("Query=%s\n", Query->GetStr());

View File

@@ -368,7 +368,7 @@ bool TDBJDBC::MakeInsert(PGLOBAL g)
char *schmp = NULL, *catp = NULL, buf[NAM_LEN * 3];
int len = 0;
uint pos;
bool b = false, oom = false;
bool b = false;
PTABLE tablep = To_Table;
PCOL colp;
@@ -405,32 +405,32 @@ bool TDBJDBC::MakeInsert(PGLOBAL g)
Query = new(g)STRING(g, len, "INSERT INTO ");
if (catp) {
oom |= Query->Append(catp);
Query->Append(catp);
if (schmp) {
oom |= Query->Append('.');
oom |= Query->Append(schmp);
Query->Append('.');
Query->Append(schmp);
} // endif schmp
oom |= Query->Append('.');
Query->Append('.');
} else if (schmp) {
oom |= Query->Append(schmp);
oom |= Query->Append('.');
Query->Append(schmp);
Query->Append('.');
} // endif schmp
if (Quote) {
// Put table name between identifier quotes in case in contains blanks
oom |= Query->Append(Quote);
oom |= Query->Append(buf);
oom |= Query->Append(Quote);
Query->Append(Quote);
Query->Append(buf);
Query->Append(Quote);
} else
oom |= Query->Append(buf);
Query->Append(buf);
oom |= Query->Append('(');
Query->Append('(');
for (colp = Columns; colp; colp = colp->GetNext()) {
if (b)
oom |= Query->Append(", ");
Query->Append(", ");
else
b = true;
@@ -439,15 +439,15 @@ bool TDBJDBC::MakeInsert(PGLOBAL g)
if (Quote) {
// Put column name between identifier quotes in case in contains blanks
oom |= Query->Append(Quote);
oom |= Query->Append(buf);
oom |= Query->Append(Quote);
Query->Append(Quote);
Query->Append(buf);
Query->Append(Quote);
} else
oom |= Query->Append(buf);
Query->Append(buf);
} // endfor colp
if ((oom |= Query->Append(") VALUES ("))) {
if ((Query->Append(") VALUES ("))) {
strcpy(g->Message, "MakeInsert: Out of memory");
return true;
} else // in case prepared statement fails
@@ -455,9 +455,9 @@ bool TDBJDBC::MakeInsert(PGLOBAL g)
// Make prepared statement
for (int i = 0; i < Nparm; i++)
oom |= Query->Append("?,");
Query->Append("?,");
if (oom) {
if (Query->IsTruncated()) {
strcpy(g->Message, "MakeInsert: Out of memory");
return true;
} else
@@ -864,7 +864,6 @@ int TDBJDBC::WriteDB(PGLOBAL g)
// an insert query for each line to insert
uint len = Query->GetLength();
char buf[64];
bool oom = false;
// Make the Insert command value list
for (PCOL colp = Columns; colp; colp = colp->GetNext()) {
@@ -872,28 +871,28 @@ int TDBJDBC::WriteDB(PGLOBAL g)
char *s = colp->GetValue()->GetCharString(buf);
if (colp->GetResultType() == TYPE_STRING)
oom |= Query->Append_quoted(s);
Query->Append_quoted(s);
else if (colp->GetResultType() == TYPE_DATE) {
DTVAL *dtv = (DTVAL*)colp->GetValue();
if (dtv->IsFormatted())
oom |= Query->Append_quoted(s);
Query->Append_quoted(s);
else
oom |= Query->Append(s);
Query->Append(s);
} else
oom |= Query->Append(s);
Query->Append(s);
} else
oom |= Query->Append("NULL");
Query->Append("NULL");
oom |= Query->Append(',');
Query->Append(',');
} // endfor colp
if (unlikely(oom)) {
if (unlikely(Query->IsTruncated())) {
strcpy(g->Message, "WriteDB: Out of memory");
return RC_FX;
} // endif oom
} // endif Query
Query->RepLast(')');

View File

@@ -586,15 +586,45 @@ PCOL TDBMGO::InsertSpecialColumn(PCOL colp)
int TDBMGO::Cardinality(PGLOBAL g)
{
if (!g)
return 0;
return 1;
else if (Cardinal < 0)
Cardinal = 10;
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;
} // endif Cardinal
bson_destroy(query);
} else
return 10;
return Cardinal;
} // end of Cardinality
/***********************************************************************/
/* MONGO GetMaxSize: returns file size estimate in number of lines. */
/* MONGO GetMaxSize: returns collection size estimate. */
/***********************************************************************/
int TDBMGO::GetMaxSize(PGLOBAL g)
{
@@ -623,104 +653,8 @@ bool TDBMGO::Init(PGLOBAL g)
} // endif p
if (*Options) {
if (trace)
htrc("options=%s\n", Options);
Opts = bson_new_from_json((const uint8_t *)Options, -1, &Error);
if (!Opts) {
sprintf(g->Message, "Wrong options: %s", Error.message);
return true;
} // endif Opts
} // endif *Options
} // endif Options
if (Pipe) {
const char *p;
if (trace)
htrc("Pipeline: %s\n", Options);
if (To_Filter) {
p = strrchr(Options, ']');
if (!p) {
strcpy(g->Message, "Missing ] in pipeline");
return true;
} else
*(char*)p = 0;
PSTRG s = new(g) STRING(g, 1023, (PSZ)Options);
s->Append(",{\"$match\":");
if (To_Filter->MakeSelector(g, s)) {
strcpy(g->Message, "Failed making selector");
return true;
} // endif Selector
s->Append("}]}");
s->Resize(s->GetLength() + 1);
p = s->GetStr();
if (trace)
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);
if (!Query) {
sprintf(g->Message, "Wrong pipeline: %s", Error.message);
return true;
} // endif Query
} else if (Filter || To_Filter) {
if (trace) {
if (Filter)
htrc("Filter: %s\n", Filter);
if (To_Filter) {
char buf[512];
To_Filter->Print(g, buf, 511);
htrc("To_Filter: %s\n", buf);
} // endif To_Filter
} // endif trace
PSTRG s = new(g) STRING(g, 1023, (PSZ)Filter);
if (To_Filter) {
if (Filter)
s->Append(',');
if (To_Filter->MakeSelector(g, s)) {
strcpy(g->Message, "Failed making selector");
return true;
} // endif Selector
s->Resize(s->GetLength() + 1);
To_Filter = NULL; // Not needed anymore
} // endif To_Filter
if (trace)
htrc("selector: %s\n", s->GetStr());
Query = bson_new_from_json((const uint8_t *)s->GetStr(), -1, &Error);
if (!Query) {
sprintf(g->Message, "Wrong filter: %s", Error.message);
return true;
} // endif Query
} else
Query = bson_new();
Uri = mongoc_uri_new(Uristr);
if (!Uri) {
@@ -765,6 +699,148 @@ bool TDBMGO::Init(PGLOBAL g)
return false;
} // end of Init
/***********************************************************************/
/* OpenDB: Data Base open routine for MONGO access method. */
/***********************************************************************/
bool TDBMGO::MakeCursor(PGLOBAL g)
{
const char *p;
PSTRG s;
if (Pipe) {
if (trace)
htrc("Pipeline: %s\n", Options);
p = strrchr(Options, ']');
if (!p) {
strcpy(g->Message, "Missing ] in pipeline");
return true;
} else
*(char*)p = 0;
s = new(g) STRING(g, 1023, (PSZ)Options);
if (To_Filter) {
s->Append(",{\"$match\":");
if (To_Filter->MakeSelector(g, s)) {
strcpy(g->Message, "Failed making selector");
return true;
} else
s->Append('}');
To_Filter = NULL; // Not needed anymore
} // endif To_Filter
// 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);
p = s->GetStr();
if (trace)
htrc("New Pipeline: %s\n", p);
Query = bson_new_from_json((const uint8_t *)p, -1, &Error);
if (!Query) {
sprintf(g->Message, "Wrong pipeline: %s", Error.message);
return true;
} // endif Query
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 (Filter)
htrc("Filter: %s\n", Filter);
if (To_Filter) {
char buf[512];
To_Filter->Print(g, buf, 511);
htrc("To_Filter: %s\n", buf);
} // endif To_Filter
} // endif trace
s = new(g) STRING(g, 1023, (PSZ)Filter);
if (To_Filter) {
if (Filter)
s->Append(',');
if (To_Filter->MakeSelector(g, s)) {
strcpy(g->Message, "Failed making selector");
return true;
} // endif Selector
To_Filter = NULL; // Not needed anymore
} // endif To_Filter
if (trace)
htrc("selector: %s\n", s->GetStr());
s->Resize(s->GetLength() + 1);
Query = bson_new_from_json((const uint8_t *)s->GetStr(), -1, &Error);
if (!Query) {
sprintf(g->Message, "Wrong filter: %s", Error.message);
return true;
} // endif Query
} else
Query = bson_new();
if (Options && *Options) {
if (trace)
htrc("options=%s\n", Options);
Opts = bson_new_from_json((const uint8_t *)Options, -1, &Error);
} else {
// Projection list
if (s)
s->Set("{\"projection\":{\"_id\":0");
else
s = new(g) STRING(g, 511, "{\"projection\":{\"_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);
Opts = bson_new_from_json((const uint8_t *)s->GetStr(), -1, &Error);
} // endif Options
if (!Opts) {
sprintf(g->Message, "Wrong options: %s", Error.message);
return true;
} // endif Opts
Cursor = mongoc_collection_find_with_opts(Collection, Query, Opts, NULL);
} // endif Pipe
return false;
} // end of MakeCursor
/***********************************************************************/
/* OpenDB: Data Base open routine for MONGO access method. */
/***********************************************************************/
@@ -797,17 +873,8 @@ bool TDBMGO::OpenDB(PGLOBAL g)
} else if (Mode == MODE_INSERT)
MakeColumnGroups(g);
else if (Pipe) {
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
Cursor = mongoc_collection_find_with_opts(Collection, Query, Opts, NULL);
else if (MakeCursor(g))
return true;
} // endif Use

View File

@@ -124,30 +124,31 @@ public:
TDBMGO(TDBMGO *tdbp);
// Implementation
virtual AMT GetAmType(void) { return TYPE_AM_MGO; }
virtual PTDB Duplicate(PGLOBAL g) { return (PTDB)new(g) TDBMGO(this); }
virtual AMT GetAmType(void) {return TYPE_AM_MGO;}
virtual PTDB Duplicate(PGLOBAL g) {return (PTDB)new(g) TDBMGO(this);}
// Methods
virtual PTDB Clone(PTABS t);
virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
virtual PCOL InsertSpecialColumn(PCOL colp);
virtual int RowNumber(PGLOBAL g, bool b = FALSE) {return N;}
virtual PTDB Clone(PTABS t);
virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
virtual PCOL InsertSpecialColumn(PCOL colp);
virtual int RowNumber(PGLOBAL g, bool b = FALSE) {return N;}
// Database routines
virtual int Cardinality(PGLOBAL g);
virtual int GetMaxSize(PGLOBAL g);
virtual bool OpenDB(PGLOBAL g);
virtual int ReadDB(PGLOBAL g);
virtual int WriteDB(PGLOBAL g);
virtual int DeleteDB(PGLOBAL g, int irc);
virtual void CloseDB(PGLOBAL g);
virtual bool ReadKey(PGLOBAL g, OPVAL op, const key_range *kr);
virtual int Cardinality(PGLOBAL g);
virtual int GetMaxSize(PGLOBAL g);
virtual bool OpenDB(PGLOBAL g);
virtual int ReadDB(PGLOBAL g);
virtual int WriteDB(PGLOBAL g);
virtual int DeleteDB(PGLOBAL g, int irc);
virtual void CloseDB(PGLOBAL g);
virtual bool ReadKey(PGLOBAL g, OPVAL op, const key_range *kr);
protected:
bool Init(PGLOBAL g);
void ShowDocument(bson_iter_t *i, const bson_t *b, const char *k);
void MakeColumnGroups(PGLOBAL g);
bool DocWrite(PGLOBAL g, PINCOL icp);
bool Init(PGLOBAL g);
bool MakeCursor(PGLOBAL g);
void ShowDocument(bson_iter_t *i, const bson_t *b, const char *k);
void MakeColumnGroups(PGLOBAL g);
bool DocWrite(PGLOBAL g, PINCOL icp);
// Members
mongoc_uri_t *Uri;

View File

@@ -495,11 +495,11 @@ PCOL TDBMYSQL::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n)
/* filter should be removed from column list. */
/***********************************************************************/
bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx)
{
{
//char *tk = "`";
char tk = '`';
int len = 0, rank = 0;
bool b = false, oom = false;
bool b = false;
PCOL colp;
//PDBUSER dup = PlgGetUser(g);
@@ -526,13 +526,13 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx)
for (colp = Columns; colp; colp = colp->GetNext())
if (!colp->IsSpecial()) {
if (b)
oom |= Query->Append(", ");
Query->Append(", ");
else
b = true;
oom |= Query->Append(tk);
oom |= Query->Append(colp->GetName());
oom |= Query->Append(tk);
Query->Append(tk);
Query->Append(colp->GetName());
Query->Append(tk);
((PMYCOL)colp)->Rank = rank++;
} // endif colp
@@ -542,22 +542,22 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx)
// Query '*' from...
// (the use of a char constant minimize the result storage)
if (Isview)
oom |= Query->Append('*');
Query->Append('*');
else
oom |= Query->Append("'*'");
Query->Append("'*'");
} // endif ncol
oom |= Query->Append(" FROM ");
oom |= Query->Append(tk);
oom |= Query->Append(TableName);
oom |= Query->Append(tk);
Query->Append(" FROM ");
Query->Append(tk);
Query->Append(TableName);
Query->Append(tk);
len = Query->GetLength();
if (To_CondFil) {
if (!mx) {
oom |= Query->Append(" WHERE ");
oom |= Query->Append(To_CondFil->Body);
Query->Append(" WHERE ");
Query->Append(To_CondFil->Body);
len = Query->GetLength() + 1;
} else
len += (strlen(To_CondFil->Body) + 256);
@@ -565,16 +565,16 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx)
} else
len += (mx ? 256 : 1);
if (oom || Query->Resize(len)) {
if (Query->IsTruncated() || Query->Resize(len)) {
strcpy(g->Message, "MakeSelect: Out of memory");
return true;
} // endif oom
} // endif Query
if (trace)
htrc("Query=%s\n", Query->GetStr());
return false;
} // end of MakeSelect
} // end of MakeSelect
/***********************************************************************/
/* MakeInsert: make the Insert statement used with MySQL connection. */
@@ -583,7 +583,7 @@ bool TDBMYSQL::MakeInsert(PGLOBAL g)
{
char *tk = "`";
uint len = 0;
bool b = false, oom;
bool oom, b = false;
PCOL colp;
if (Query)
@@ -622,38 +622,38 @@ bool TDBMYSQL::MakeInsert(PGLOBAL g)
Query = new(g) STRING(g, len);
if (Delayed)
oom = Query->Set("INSERT DELAYED INTO ");
Query->Set("INSERT DELAYED INTO ");
else
oom = Query->Set("INSERT INTO ");
Query->Set("INSERT INTO ");
oom |= Query->Append(tk);
oom |= Query->Append(TableName);
oom |= Query->Append("` (");
Query->Append(tk);
Query->Append(TableName);
Query->Append("` (");
for (colp = Columns; colp; colp = colp->GetNext()) {
if (b)
oom |= Query->Append(", ");
Query->Append(", ");
else
b = true;
oom |= Query->Append(tk);
oom |= Query->Append(colp->GetName());
oom |= Query->Append(tk);
Query->Append(tk);
Query->Append(colp->GetName());
Query->Append(tk);
} // endfor colp
oom |= Query->Append(") VALUES (");
Query->Append(") VALUES (");
#if defined(MYSQL_PREPARED_STATEMENTS)
if (Prep) {
for (int i = 0; i < Nparm; i++)
oom |= Query->Append("?,");
Query->Append("?,");
Query->RepLast(')');
Query->Trim();
} // endif Prep
#endif // MYSQL_PREPARED_STATEMENTS
if (oom)
if ((oom = Query->IsTruncated()))
strcpy(g->Message, "MakeInsert: Out of memory");
return oom;
@@ -684,18 +684,18 @@ bool TDBMYSQL::MakeCommand(PGLOBAL g)
strlwr(strcpy(name, Name)); // Not a keyword
if ((p = strstr(qrystr, name))) {
bool oom = Query->Set(Qrystr, p - qrystr);
Query->Set(Qrystr, p - qrystr);
if (qtd && *(p-1) == ' ') {
oom |= Query->Append('`');
oom |= Query->Append(TableName);
oom |= Query->Append('`');
Query->Append('`');
Query->Append(TableName);
Query->Append('`');
} 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");
return true;
} else
@@ -1161,24 +1161,23 @@ int TDBMYSQL::WriteDB(PGLOBAL g)
int rc;
uint len = Query->GetLength();
char buf[64];
bool oom = false;
// Make the Insert command value list
for (PCOL colp = Columns; colp; colp = colp->GetNext()) {
if (!colp->GetValue()->IsNull()) {
if (colp->GetResultType() == TYPE_STRING ||
colp->GetResultType() == TYPE_DATE)
oom |= Query->Append_quoted(colp->GetValue()->GetCharString(buf));
Query->Append_quoted(colp->GetValue()->GetCharString(buf));
else
oom |= Query->Append(colp->GetValue()->GetCharString(buf));
Query->Append(colp->GetValue()->GetCharString(buf));
} else
oom |= Query->Append("NULL");
Query->Append("NULL");
oom |= Query->Append(',');
Query->Append(',');
} // endfor colp
if (unlikely(oom)) {
if (unlikely(Query->IsTruncated())) {
strcpy(g->Message, "WriteDB: Out of memory");
rc = RC_FX;
} else {
@@ -1186,7 +1185,7 @@ int TDBMYSQL::WriteDB(PGLOBAL g)
Myc.m_Rows = -1; // To execute the query
rc = Myc.ExecSQL(g, Query->GetStr());
Query->Truncate(len); // Restore query
} // endif oom
} // endif Query
return (rc == RC_NF) ? RC_OK : rc; // RC_NF is Ok
} // end of WriteDB

View File

@@ -109,7 +109,7 @@ class TDBMYSQL : public TDBEXT {
// Internal functions
bool MakeSelect(PGLOBAL g, bool mx);
bool MakeInsert(PGLOBAL g);
int BindColumns(PGLOBAL g);
int BindColumns(PGLOBAL g __attribute__((unused)));
virtual bool MakeCommand(PGLOBAL g);
//int MakeUpdate(PGLOBAL g);
//int MakeDelete(PGLOBAL g);

View File

@@ -299,7 +299,7 @@ bool TDBODBC::MakeInsert(PGLOBAL g)
{
char *schmp = NULL, *catp = NULL, buf[NAM_LEN * 3];
int len = 0;
bool b = false, oom = false;
bool oom, b = false;
PTABLE tablep = To_Table;
PCOL colp;
@@ -336,32 +336,32 @@ bool TDBODBC::MakeInsert(PGLOBAL g)
Query = new(g) STRING(g, len, "INSERT INTO ");
if (catp) {
oom |= Query->Append(catp);
Query->Append(catp);
if (schmp) {
oom |= Query->Append('.');
oom |= Query->Append(schmp);
Query->Append('.');
Query->Append(schmp);
} // endif schmp
oom |= Query->Append('.');
Query->Append('.');
} else if (schmp) {
oom |= Query->Append(schmp);
oom |= Query->Append('.');
Query->Append(schmp);
Query->Append('.');
} // endif schmp
if (Quote) {
// Put table name between identifier quotes in case in contains blanks
oom |= Query->Append(Quote);
oom |= Query->Append(buf);
oom |= Query->Append(Quote);
Query->Append(Quote);
Query->Append(buf);
Query->Append(Quote);
} else
oom |= Query->Append(buf);
Query->Append(buf);
oom |= Query->Append('(');
Query->Append('(');
for (colp = Columns; colp; colp = colp->GetNext()) {
if (b)
oom |= Query->Append(", ");
Query->Append(", ");
else
b = true;
@@ -370,20 +370,20 @@ bool TDBODBC::MakeInsert(PGLOBAL g)
if (Quote) {
// Put column name between identifier quotes in case in contains blanks
oom |= Query->Append(Quote);
oom |= Query->Append(buf);
oom |= Query->Append(Quote);
Query->Append(Quote);
Query->Append(buf);
Query->Append(Quote);
} else
oom |= Query->Append(buf);
Query->Append(buf);
} // endfor colp
oom |= Query->Append(") VALUES (");
Query->Append(") VALUES (");
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");
else
Query->RepLast(')');

View File

@@ -192,7 +192,7 @@ void CONSTANT::Print(PGLOBAL g, char *ps, uint z)
/* STRING public constructor for new char values. Alloc Size must be */
/* 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;
Length = (str) ? strlen(str) : 0;
@@ -205,10 +205,12 @@ STRING::STRING(PGLOBAL g, uint n, char *str)
Next = GetNext();
Size = Next - Strp;
Trc = false;
} else {
// This should normally never happen
Next = NULL;
Size = 0;
Trc = true;
} // endif Strp
} // end of STRING constructor
@@ -229,6 +231,7 @@ char *STRING::Realloc(uint len)
if (!p) {
// No more room in Sarea; this is very unlikely
strcpy(G->Message, "No more room in work area");
Trc = true;
return NULL;
} // endif p

View File

@@ -130,6 +130,7 @@ class DllExport STRING : public BLOCK {
inline void SetLength(uint n) {Length = n;}
inline PSZ GetStr(void) {return Strp;}
inline uint32 GetSize(void) {return Size;}
inline bool IsTruncated(void) {return Trc;}
// Methods
inline void Reset(void) {*Strp = 0;}
@@ -156,6 +157,7 @@ class DllExport STRING : public BLOCK {
PSZ Strp; // The char string
uint Length; // String length
uint Size; // Allocated size
bool Trc; // When truncated
char *Next; // Next alloc position
}; // end of class STRING