Przeglądaj źródła

HPCC-10461 Add additional plugins for external databases

Added initial version of MySQL embed support

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 11 lat temu
rodzic
commit
b4563db4fb

+ 1 - 0
cmake_modules/commonSetup.cmake

@@ -73,6 +73,7 @@ IF ("${COMMONSETUP_DONE}" STREQUAL "")
   option(USE_RESOURCE "Use resource download in ECLWatch" OFF)
   option(GENERATE_COVERAGE_INFO "Generate coverage info for gcov" OFF)
 
+  option(USE_MYSQL "Enable MySQL support" ON)
   option(USE_SQLITE3 "Enable SqLite3 support" ON)
   option(USE_PYTHON "Enable Python support" ON)
   option(USE_V8 "Enable V8 JavaScript support" ON)

+ 2 - 0
ecl/hqlcpp/hqlcpp.cpp

@@ -11708,6 +11708,8 @@ void HqlCppTranslator::buildScriptFunctionDefinition(BuildCtx &funcctx, IHqlExpr
         returnFunc = getTransformResultId;
         newReturnType.set(returnType);
         break;
+    case type_void:
+        return;
     default:
         StringBuffer typeText;
         getFriendlyTypeStr(returnType, typeText);

+ 1 - 0
plugins/CMakeLists.txt

@@ -23,6 +23,7 @@ add_subdirectory (unicodelib)
 add_subdirectory (workunitservices)
 add_subdirectory (proxies)
 add_subdirectory (sqlite3)
+add_subdirectory (mysql)
 add_subdirectory (v8embed)
 add_subdirectory (pyembed)
 add_subdirectory (javaembed)

+ 64 - 0
plugins/mysql/CMakeLists.txt

@@ -0,0 +1,64 @@
+################################################################################
+#    HPCC SYSTEMS software Copyright (C) 2013 HPCC Systems.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+################################################################################
+
+
+# Component: mysqlembed
+
+#####################################################
+# Description:
+# ------------
+#    Cmake Input File for mysqlembed
+#####################################################
+
+project( mysqlembed )
+
+if (USE_MYSQL)
+  ADD_PLUGIN(mysqlembed PACKAGES mysql-client OPTION MAKE_MYSQL)
+  if ( 1 ) # MAKE_MYSQL )
+    set ( SRCS
+          mysqlembed.cpp
+        )
+
+    include_directories (
+         ./../../system/include
+         ./../../rtl/eclrtl
+         ./../../rtl/include
+         ./../../rtl/nbcd
+         ./../../common/deftype
+         ./../../system/jlib
+         ${MYSQL_INCLUDE_DIR}
+       )
+
+    ADD_DEFINITIONS( -D_USRDLL -DMYSQLEMBED_EXPORTS )
+
+    HPCC_ADD_LIBRARY( mysqlembed SHARED ${SRCS} )
+    if (${CMAKE_VERSION} VERSION_LESS "2.8.9")
+      message("WARNING: Cannot set NO_SONAME. shlibdeps will give warnings when package is installed")
+    else()
+      set_target_properties( mysqlembed PROPERTIES NO_SONAME 1 )
+    endif()
+
+    install ( TARGETS mysqlembed DESTINATION plugins )
+    target_link_libraries ( mysqlembed
+         ${MYSQL_LIBRARIES}
+        eclrtl
+        jlib
+        )
+  endif()
+endif()
+
+# Even if not making the MySQL plugin, we want to install the header
+install ( FILES ${CMAKE_CURRENT_SOURCE_DIR}/mysql.ecllib DESTINATION plugins COMPONENT Runtime)

+ 25 - 0
plugins/mysql/mysql.ecllib

@@ -0,0 +1,25 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2013 HPCC Systems.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+############################################################################## */
+
+EXPORT Language := SERVICE : plugin('mysqlembed')
+  boolean getEmbedContext():cpp,pure,namespace='mysqlembed',entrypoint='getEmbedContext',prototype='IEmbedContext* getEmbedContext()';
+  boolean syntaxCheck(const varstring src):cpp,pure,namespace='mysqlembed',entrypoint='syntaxCheck';
+END;
+EXPORT getEmbedContext := Language.getEmbedContext;
+EXPORT syntaxCheck := Language.syntaxCheck;
+EXPORT boolean supportsImport := false;
+EXPORT boolean supportsScript := true;

Plik diff jest za duży
+ 1045 - 0
plugins/mysql/mysqlembed.cpp


+ 1 - 4
plugins/sqlite3/sqlite3.cpp

@@ -63,10 +63,7 @@ extern "C" EXPORT bool getECLPluginDefinition(ECLPluginDefinitionBlock *pb)
 
 namespace sqlite3embed {
 
-// Use class OwnedPyObject for any objects that are not 'borrowed references'
-// so that the appropriate Py_DECREF call is made when the OwnedPyObject goes
-// out of scope, even if the function returns prematurely (such as via an exception).
-// In particular, checkPythonError is a lot easier to call safely if this is used.
+// Use class OwnedStatement for a sqlite3 stmt object that needs to be released cleanly
 
 class OwnedStatement
 {

+ 37 - 0
testing/ecl/key/mysqlembed.xml

@@ -0,0 +1,37 @@
+<Dataset name='Result 1'>
+ <Row><name>name1</name><value>1</value><boolval>true</boolval><r8>1.2</r8><r4>3.400000095367432</r4><d>6161353561613535</d><ddd>1234567.89</ddd><u1>Straße</u1><u2>Straße  </u2></Row>
+ <Row><name>name2</name><value>2</value><boolval>false</boolval><r8>5.6</r8><r4>7.800000190734863</r4><d>3030</d><ddd>-1234567.89</ddd><u1>là</u1><u2>là      </u2></Row>
+</Dataset>
+<Dataset name='Result 2'>
+ <Row><Result_2>name1</Result_2></Row>
+</Dataset>
+<Dataset name='Result 3'>
+ <Row><name>name1</name><value>1</value><boolval>true</boolval><r8>1.2</r8><r4>3.400000095367432</r4><d>6161353561613535</d><ddd>1234567.89</ddd><u1>Straße</u1><u2>Straße  </u2></Row>
+</Dataset>
+<Dataset name='Result 4'>
+ <Row><Result_4>name2</Result_4></Row>
+</Dataset>
+<Dataset name='Result 5'>
+ <Row><name>name2</name><value>2</value><boolval>false</boolval><r8>5.6</r8><r4>7.800000190734863</r4><d>3030</d><ddd>-1234567.89</ddd><u1>là</u1><u2>là      </u2></Row>
+</Dataset>
+<Dataset name='Result 6'>
+ <Row><Result_6>2</Result_6></Row>
+</Dataset>
+<Dataset name='Result 7'>
+ <Row><Result_7>true</Result_7></Row>
+</Dataset>
+<Dataset name='Result 8'>
+ <Row><Result_8>5.6</Result_8></Row>
+</Dataset>
+<Dataset name='Result 9'>
+ <Row><Result_9>7.800000190734863</Result_9></Row>
+</Dataset>
+<Dataset name='Result 10'>
+ <Row><Result_10>6161353561613535</Result_10></Row>
+</Dataset>
+<Dataset name='Result 11'>
+ <Row><Result_11>Straße</Result_11></Row>
+</Dataset>
+<Dataset name='Result 12'>
+ <Row><Result_12>Straße  </Result_12></Row>
+</Dataset>

+ 119 - 0
testing/ecl/mysqlembed.ecl

@@ -0,0 +1,119 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2013 HPCC Systems.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+############################################################################## */
+
+IMPORT mysql;
+
+childrec := RECORD
+   string name,
+   integer value,
+   boolean boolval,
+   real8 r8,
+   real4 r4,
+   DATA d,
+   DECIMAL10_2 ddd,
+   UTF8 u1,
+   UNICODE8 u2
+END;
+
+init := DATASET([{'name1', 1, true, 1.2, 3.4, D'aa55aa55', 1234567.89, U'Straße', U'Straße'},
+                 {'name2', 2, false, 5.6, 7.8, D'00', -1234567.89, U'là', U'là'}], childrec);
+
+drop() := EMBED(mysql : user('rchapman'),database('test'))
+  DROP TABLE IF EXISTS tbl1;
+ENDEMBED;
+
+create() := EMBED(mysql : user('rchapman'),database('test'))
+  CREATE TABLE tbl1 ( name VARCHAR(20), value INT, boolval TINYINT, r8 DOUBLE, r4 FLOAT, d BLOB, ddd DECIMAL(10,2), u1 VARCHAR(10), u2 VARCHAR(10) );
+ENDEMBED;
+
+initialize(dataset(childrec) values) := EMBED(mysql : user('rchapman'),database('test'))
+  INSERT INTO tbl1 values (?, ?, ?, ?, ?, ?, ?, ?, ?);
+ENDEMBED;
+
+dataset(childrec) testMySQLDS() := EMBED(mysql : user('rchapman'),database('test'))
+  SELECT * from tbl1;
+ENDEMBED;
+
+childrec testMySQLRow() := EMBED(mysql : user('rchapman'),database('test'))
+  SELECT * from tbl1 LIMIT 1;
+ENDEMBED;
+
+childrec testMySQLParms(
+   string name,
+   integer value,
+   boolean boolval,
+   real8 r8,
+   real4 r4,
+   DATA d,
+   UTF8 u1,
+   UNICODE8 u2) := EMBED(mysql : user('rchapman'),database('test'))
+  SELECT * from tbl1 WHERE name=? AND value=? AND boolval=? AND r8=? AND r4=? AND d=? AND u1=? AND u2=?;
+ENDEMBED;
+
+string testMySQLString() := EMBED(mysql : user('rchapman'),database('test'))
+  SELECT max(name) from tbl1;
+ENDEMBED;
+
+dataset(childrec) testMySQLStringParam(string filter) := EMBED(mysql : user('rchapman'),database('test'))
+  SELECT * from tbl1 where name = ?;
+ENDEMBED;
+
+integer testMySQLInt() := EMBED(mysql : user('rchapman'),database('test'))
+  SELECT max(value) from tbl1;
+ENDEMBED;
+
+boolean testMySQLBool() := EMBED(mysql : user('rchapman'),database('test'))
+  SELECT max(boolval) from tbl1;
+ENDEMBED;
+
+real8 testMySQLReal8() := EMBED(mysql : user('rchapman'),database('test'))
+  SELECT max(r8) from tbl1;
+ENDEMBED;
+
+real4 testMySQLReal4() := EMBED(mysql : user('rchapman'),database('test'))
+  SELECT max(r4) from tbl1;
+ENDEMBED;
+
+data testMySQLData() := EMBED(mysql : user('rchapman'),database('test'))
+  SELECT max(d) from tbl1;
+ENDEMBED;
+
+UTF8 testMySQLUtf8() := EMBED(mysql : user('rchapman'),database('test'))
+  SELECT max(u1) from tbl1;
+ENDEMBED;
+
+UNICODE testMySQLUnicode() := EMBED(mysql : user('rchapman'),database('test'))
+  SELECT max(u2) from tbl1;
+ENDEMBED;
+
+sequential (
+  drop(),
+  create(),
+  initialize(init),
+  OUTPUT(testMySQLDS()),
+  OUTPUT(testMySQLRow().name),
+  OUTPUT(testMySQLParms('name1', 1, true, 1.2, 3.4, D'aa55aa55', U'Straße', U'Straße')),
+  OUTPUT(testMySQLString()),
+  OUTPUT(testMySQLStringParam(testMySqlString())),
+  OUTPUT(testMySQLInt()),
+  OUTPUT(testMySQLBool()),
+  OUTPUT(testMySQLReal8()),
+  OUTPUT(testMySQLReal4()),
+  OUTPUT(testMySQLData()),
+  OUTPUT(testMySQLUtf8()),
+  OUTPUT(testMySQLUnicode())
+);