transactd 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/BUILD_UNIX-JA +46 -67
- data/BUILD_WIN-JA +106 -63
- data/CMakeLists.txt +40 -15
- data/README +219 -75
- data/README-JA +207 -76
- data/README_ORMSRCGEN +118 -0
- data/README_ORMSRCGEN-JA +115 -0
- data/bin/common/tdclc_32_2_0.dll +0 -0
- data/bin/common/tdclc_64_2_0.dll +0 -0
- data/build/common/check_for_link_iconv.cmake +18 -14
- data/build/common/create_symlink.cmake.in +25 -0
- data/build/common/get_boost_libs.cmake +23 -23
- data/build/common/options.cmake +0 -66
- data/build/common/smart_install.cmake +3 -3
- data/build/common/transactd.rc.in +15 -5
- data/build/common/transactd_cl_common.cmake +37 -18
- data/build/common/transactd_cl_output.cmake +55 -13
- data/build/common/transactd_common.cmake +108 -31
- data/build/swig/php/generate.cmake.in +15 -17
- data/build/swig/php/generate.cmd.in +15 -9
- data/build/swig/php/php.swg +124 -82
- data/build/swig/php/transactd.no_yield.php +4494 -0
- data/build/swig/php/transactd.no_yield.php.git.patch +685 -0
- data/build/swig/php/transactd.no_yield.php.patch +685 -0
- data/build/swig/php/transactd.yield.php +4461 -0
- data/build/swig/php/transactd.yield.php.git.patch +652 -0
- data/build/swig/php/transactd.yield.php.patch +652 -0
- data/build/swig/referencecounter.h +79 -0
- data/build/swig/ruby/ruby.swg +226 -76
- data/build/swig/ruby/threadBlockRegionWrapper.h +71 -0
- data/build/swig/ruby/without_gvl.swg +87 -0
- data/build/swig/tdcl.i +659 -170
- data/build/swig/validatablepointer.h +91 -0
- data/build/tdclc/CMakeLists.txt +49 -34
- data/build/tdclc/{tdclc_64.cbproj → tdclc.cbproj} +65 -20
- data/build/tdclc/tdclc.rc +0 -0
- data/build/tdclcpp/CMakeLists.txt +84 -20
- data/build/tdclcpp/tdclcpp.rc +0 -0
- data/build/tdclcpp/{tdclcpp_bcb_64.cbproj → tdclcpp_bc.cbproj} +168 -44
- data/build/tdclrb/CMakeLists.txt +84 -66
- data/build/tdclrb/bldgem/extconf.rb +28 -3
- data/build/tdclrb/gem/helper.rb +11 -1
- data/build/tdclrb/gem_output.cmake +20 -16
- data/index_ja.html +15 -0
- data/source/bzs/db/IBlobBuffer.h +15 -17
- data/source/bzs/db/blobBuffer.h +186 -140
- data/source/bzs/db/blobStructs.h +37 -37
- data/source/bzs/db/engine/mysql/IReadRecords.h +34 -34
- data/source/bzs/db/engine/mysql/bookmark.h +150 -147
- data/source/bzs/db/engine/mysql/database.cpp +1721 -1526
- data/source/bzs/db/engine/mysql/database.h +608 -370
- data/source/bzs/db/engine/mysql/dbManager.cpp +213 -201
- data/source/bzs/db/engine/mysql/dbManager.h +115 -104
- data/source/bzs/db/engine/mysql/errorMessage.cpp +49 -50
- data/source/bzs/db/engine/mysql/errorMessage.h +25 -26
- data/source/bzs/db/engine/mysql/fieldAccess.h +55 -61
- data/source/bzs/db/engine/mysql/mydebuglog.cpp +326 -292
- data/source/bzs/db/engine/mysql/mydebuglog.h +63 -55
- data/source/bzs/db/engine/mysql/mysqlInternal.h +182 -125
- data/source/bzs/db/engine/mysql/mysqlThd.cpp +121 -121
- data/source/bzs/db/engine/mysql/mysqlThd.h +20 -20
- data/source/bzs/db/engine/mysql/percentageKey.h +241 -228
- data/source/bzs/db/protocol/ICommandExecuter.h +18 -17
- data/source/bzs/db/protocol/hs/hsCommandExecuter.cpp +543 -514
- data/source/bzs/db/protocol/hs/hsCommandExecuter.h +155 -158
- data/source/bzs/db/protocol/tdap/btrDate.cpp +213 -180
- data/source/bzs/db/protocol/tdap/btrDate.h +39 -37
- data/source/bzs/db/protocol/tdap/client/activeTable.cpp +173 -0
- data/source/bzs/db/protocol/tdap/client/activeTable.h +165 -0
- data/source/bzs/db/protocol/tdap/client/activeTableImple.h +370 -0
- data/source/bzs/db/protocol/tdap/client/bulkInsert.h +13 -23
- data/source/bzs/db/protocol/tdap/client/client.cpp +81 -68
- data/source/bzs/db/protocol/tdap/client/client.h +361 -320
- data/source/bzs/db/protocol/tdap/client/connMgr.cpp +17 -22
- data/source/bzs/db/protocol/tdap/client/connMgr.h +17 -19
- data/source/bzs/db/protocol/tdap/client/connectionPool.cpp +243 -0
- data/source/bzs/db/protocol/tdap/client/connectionPool.h +109 -0
- data/source/bzs/db/protocol/tdap/client/database.cpp +327 -219
- data/source/bzs/db/protocol/tdap/client/database.h +141 -118
- data/source/bzs/db/protocol/tdap/client/databaseFactory.cpp +60 -62
- data/source/bzs/db/protocol/tdap/client/databaseManager.h +255 -0
- data/source/bzs/db/protocol/tdap/client/dbDef.cpp +315 -202
- data/source/bzs/db/protocol/tdap/client/dbDef.h +40 -32
- data/source/bzs/db/protocol/tdap/client/dllmain.cpp +390 -371
- data/source/bzs/db/protocol/tdap/client/errorMessage.cpp +148 -56
- data/source/bzs/db/protocol/tdap/client/errorMessage_ja.cpp +149 -57
- data/source/bzs/db/protocol/tdap/client/export.h +35 -0
- data/source/bzs/db/protocol/tdap/client/field.cpp +1985 -0
- data/source/bzs/db/protocol/tdap/client/field.h +393 -0
- data/source/bzs/db/protocol/tdap/client/fieldDDF.cpp +14 -14
- data/source/bzs/db/protocol/tdap/client/fieldDDF.h +11 -14
- data/source/bzs/db/protocol/tdap/client/fieldNameAlias.cpp +123 -0
- data/source/bzs/db/protocol/tdap/client/fieldNameAlias.h +58 -0
- data/source/bzs/db/protocol/tdap/client/fields.h +178 -0
- data/source/bzs/db/protocol/tdap/client/fileDDF.cpp +13 -16
- data/source/bzs/db/protocol/tdap/client/fileDDF.h +11 -17
- data/source/bzs/db/protocol/tdap/client/filter.h +423 -259
- data/source/bzs/db/protocol/tdap/client/groupComp.h +117 -0
- data/source/bzs/db/protocol/tdap/client/groupQuery.cpp +818 -0
- data/source/bzs/db/protocol/tdap/client/groupQuery.h +281 -0
- data/source/bzs/db/protocol/tdap/client/indexDDF.cpp +14 -17
- data/source/bzs/db/protocol/tdap/client/indexDDF.h +11 -14
- data/source/bzs/db/protocol/tdap/client/memRecord.cpp +231 -0
- data/source/bzs/db/protocol/tdap/client/memRecord.h +145 -0
- data/source/bzs/db/protocol/tdap/client/memRecordset.cpp +448 -0
- data/source/bzs/db/protocol/tdap/client/memRecordset.h +159 -0
- data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +300 -173
- data/source/bzs/db/protocol/tdap/client/nsDatabase.h +53 -36
- data/source/bzs/db/protocol/tdap/client/nsTable.cpp +171 -128
- data/source/bzs/db/protocol/tdap/client/nsTable.h +121 -87
- data/source/bzs/db/protocol/tdap/client/pooledDatabaseManager.h +173 -0
- data/source/bzs/db/protocol/tdap/client/recordset.cpp +209 -0
- data/source/bzs/db/protocol/tdap/client/recordset.h +86 -0
- data/source/bzs/db/protocol/tdap/client/recordsetImple.h +596 -0
- data/source/bzs/db/protocol/tdap/client/request.h +227 -170
- data/source/bzs/db/protocol/tdap/client/serializer.cpp +1288 -0
- data/source/bzs/db/protocol/tdap/client/serializer.h +295 -0
- data/source/bzs/db/protocol/tdap/client/sharedData.cpp +9 -12
- data/source/bzs/db/protocol/tdap/client/sharedData.h +18 -16
- data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +494 -473
- data/source/bzs/db/protocol/tdap/client/sqlBuilder.h +51 -53
- data/source/bzs/db/protocol/tdap/client/stringConverter.h +214 -148
- data/source/bzs/db/protocol/tdap/client/table.cpp +929 -1665
- data/source/bzs/db/protocol/tdap/client/table.h +413 -87
- data/source/bzs/db/protocol/tdap/client/trdboostapi.h +642 -534
- data/source/bzs/db/protocol/tdap/client/trdboostapiInternal.h +25 -40
- data/source/bzs/db/protocol/tdap/client/trdclcppautolink.h +11 -15
- data/source/bzs/db/protocol/tdap/client/trdormapi.h +378 -437
- data/source/bzs/db/protocol/tdap/client/trnsctcl.def +1 -1
- data/source/bzs/db/protocol/tdap/fieldComp.h +127 -0
- data/source/bzs/db/protocol/tdap/myDateTime.cpp +352 -345
- data/source/bzs/db/protocol/tdap/mysql/characterset.cpp +75 -78
- data/source/bzs/db/protocol/tdap/mysql/characterset.h +18 -19
- data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +216 -199
- data/source/bzs/db/protocol/tdap/mysql/databaseSchema.h +23 -14
- data/source/bzs/db/protocol/tdap/mysql/debuglog.cpp +354 -314
- data/source/bzs/db/protocol/tdap/mysql/debuglog.h +57 -47
- data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +905 -739
- data/source/bzs/db/protocol/tdap/mysql/request.h +152 -159
- data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +1044 -879
- data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +87 -81
- data/source/bzs/db/protocol/tdap/tdapRequest.h +162 -130
- data/source/bzs/db/protocol/tdap/tdapSchema.cpp +368 -166
- data/source/bzs/db/protocol/tdap/tdapSchema.h +702 -566
- data/source/bzs/db/protocol/tdap/tdapcapi.h +387 -353
- data/source/bzs/db/transactd/appBuilderImple.h +21 -20
- data/source/bzs/db/transactd/appModule.cpp +350 -98
- data/source/bzs/db/transactd/appModule.h +31 -37
- data/source/bzs/db/transactd/connManager.cpp +138 -135
- data/source/bzs/db/transactd/connManager.h +28 -21
- data/source/bzs/db/transactd/connectionRecord.h +39 -39
- data/source/bzs/db/transactd/transactd.cpp +217 -203
- data/source/bzs/env/boost_bcb_link.h +131 -0
- data/source/bzs/env/compiler.h +136 -79
- data/source/bzs/env/crosscompile.cpp +57 -57
- data/source/bzs/env/crosscompile.h +130 -115
- data/source/bzs/env/fileopen.h +7 -8
- data/source/bzs/env/mbcswchrLinux.cpp +4 -9
- data/source/bzs/env/mbcswchrLinux.h +37 -34
- data/source/bzs/env/tcharMinGW.h +59 -0
- data/source/bzs/env/tstring.h +90 -95
- data/source/bzs/example/changeSchema.cpp +22 -23
- data/source/bzs/example/changeSchema_c.cpp +22 -24
- data/source/bzs/example/connection_pool_c.cpp +49 -104
- data/source/bzs/example/createDatabase.cpp +40 -47
- data/source/bzs/example/createDatabase_c.cpp +38 -43
- data/source/bzs/example/deleteRecords.cpp +10 -15
- data/source/bzs/example/deleteRecords_c.cpp +10 -14
- data/source/bzs/example/dropDatabase.cpp +3 -9
- data/source/bzs/example/dropDatabase_c.cpp +5 -6
- data/source/bzs/example/insertRecords.cpp +37 -29
- data/source/bzs/example/insertRecords_c.cpp +19 -25
- data/source/bzs/example/ormap_c.cpp +621 -0
- data/source/bzs/example/queryData.cpp +371 -0
- data/source/bzs/example/queryData.h +16 -0
- data/source/bzs/example/query_c.cpp +109 -0
- data/source/bzs/example/readRecords.cpp +27 -27
- data/source/bzs/example/readRecords_c.cpp +25 -23
- data/source/bzs/example/updateRecords.cpp +16 -21
- data/source/bzs/example/updateRecords_c.cpp +8 -12
- data/source/bzs/example/update_with_transaction.cpp +21 -24
- data/source/bzs/example/update_with_transaction_c.cpp +12 -15
- data/source/bzs/example/useORMRecord.cpp +177 -0
- data/source/bzs/netsvc/client/tcpClient.cpp +167 -156
- data/source/bzs/netsvc/client/tcpClient.h +541 -489
- data/source/bzs/netsvc/server/IAppModule.h +119 -32
- data/source/bzs/netsvc/server/iserver.h +21 -23
- data/source/bzs/netsvc/server/serverCpt.cpp +421 -391
- data/source/bzs/netsvc/server/serverCpt.h +41 -43
- data/source/bzs/netsvc/server/serverPipe.cpp +580 -565
- data/source/bzs/netsvc/server/serverPipe.h +44 -45
- data/source/bzs/netsvc/server/serverTpool.cpp +333 -303
- data/source/bzs/netsvc/server/serverTpool.h +38 -43
- data/source/bzs/rtl/benchmark.cpp +91 -31
- data/source/bzs/rtl/benchmark.h +76 -22
- data/source/bzs/rtl/datetime.cpp +231 -233
- data/source/bzs/rtl/datetime.h +16 -16
- data/source/bzs/rtl/debuglog.cpp +48 -51
- data/source/bzs/rtl/debuglog.h +55 -44
- data/source/bzs/rtl/exception.h +55 -48
- data/source/bzs/rtl/stl_uty.cpp +27 -28
- data/source/bzs/rtl/stl_uty.h +28 -29
- data/source/bzs/rtl/stringBuffers.cpp +8 -6
- data/source/bzs/rtl/stringBuffers.h +16 -9
- data/source/bzs/rtl/strtrim.cpp +90 -91
- data/source/bzs/rtl/strtrim.h +14 -16
- data/source/bzs/test/tdclatl/bench_query_atl.js +647 -0
- data/source/bzs/test/tdclatl/bench_tdclatl.js +303 -303
- data/source/bzs/test/tdclatl/test_query_atl.js +669 -0
- data/source/bzs/test/tdclphp/bench.php +357 -0
- data/source/bzs/test/tdclphp/transactd_Test.php +907 -303
- data/source/bzs/test/tdclphp/transactd_blob_Test.php +21 -49
- data/source/bzs/test/tdclphp/transactd_datetime_Test.php +41 -75
- data/source/bzs/test/tdclphp/transactd_kanjischema_Test.php +23 -37
- data/source/bzs/test/tdclphp/transactd_pool_Test.php +120 -0
- data/source/bzs/test/tdclrb/bench_tdclcpp.rb +4 -6
- data/source/bzs/test/tdclrb/prepare.rb +15 -12
- data/source/bzs/test/tdclrb/transactd_blob_spec.rb +29 -32
- data/source/bzs/test/tdclrb/transactd_datetime_spec.rb +0 -29
- data/source/bzs/test/tdclrb/transactd_kanjischema_spec.rb +18 -19
- data/source/bzs/test/tdclrb/transactd_pool_spec.rb +107 -0
- data/source/bzs/test/tdclrb/transactd_spec.rb +734 -142
- data/source/bzs/test/transactdBench/query_bench.cpp +156 -0
- data/source/bzs/test/transactdBench/scaling_bench.cpp +265 -0
- data/source/bzs/test/transactdBench/transactdBench.cpp +107 -83
- data/source/bzs/test/transactdBench/transactdBench2.cpp +122 -83
- data/source/bzs/test/transactdBench/workerBase.cpp +5 -0
- data/source/bzs/test/transactdBench/workerBase.h +88 -0
- data/source/bzs/test/transactdBench/workerMySQLImple.h +333 -0
- data/source/bzs/test/transactdBench/workerTransactdImple.h +201 -0
- data/source/bzs/test/trdclengn/test_blob.cpp +121 -73
- data/source/bzs/test/trdclengn/test_trdclengn.cpp +1244 -426
- data/source/global/ormsrcgen/confParam.h +80 -0
- data/source/global/ormsrcgen/fieldName.cpp +77 -0
- data/source/global/ormsrcgen/fieldName.h +43 -0
- data/source/global/ormsrcgen/main.cpp +196 -0
- data/source/global/ormsrcgen/srcgen.cpp +763 -0
- data/source/global/ormsrcgen/srcgen.h +72 -0
- data/source/global/ormsrcgen/template/fieldNameList_sample.txt +2 -0
- data/source/global/ormsrcgen/template/ormDataClass_template.cpp +48 -0
- data/source/global/ormsrcgen/template/ormDataClass_template.h +34 -0
- data/source/global/ormsrcgen/template/ormMapClass_template.cpp +51 -0
- data/source/global/ormsrcgen/template/ormMapClass_template.h +62 -0
- data/source/global/ormsrcgen/template/template.cnf +38 -0
- data/source/global/querystmts/querystmts.cpp +237 -0
- data/source/global/tdclatl/ConnectParams.cpp +77 -0
- data/source/global/tdclatl/ConnectParams.h +70 -0
- data/source/global/tdclatl/Database.cpp +132 -128
- data/source/global/tdclatl/Database.h +60 -49
- data/source/global/tdclatl/DbDef.cpp +68 -64
- data/source/global/tdclatl/DbDef.h +36 -36
- data/source/global/tdclatl/Field.cpp +12 -17
- data/source/global/tdclatl/Field.h +15 -12
- data/source/global/tdclatl/FieldDef.cpp +75 -36
- data/source/global/tdclatl/FieldDef.h +38 -19
- data/source/global/tdclatl/FieldDefs.cpp +74 -0
- data/source/global/tdclatl/FieldDefs.h +56 -0
- data/source/global/tdclatl/FieldNames.cpp +99 -0
- data/source/global/tdclatl/FieldNames.h +66 -0
- data/source/global/tdclatl/Flags.cpp +75 -37
- data/source/global/tdclatl/Flags.h +13 -12
- data/source/global/tdclatl/GroupQuery.cpp +119 -0
- data/source/global/tdclatl/GroupQuery.h +65 -0
- data/source/global/tdclatl/KeyDef.cpp +15 -14
- data/source/global/tdclatl/KeyDef.h +20 -17
- data/source/global/tdclatl/KeySegment.cpp +13 -12
- data/source/global/tdclatl/PooledDbManager.cpp +223 -0
- data/source/global/tdclatl/PooledDbManager.h +76 -0
- data/source/global/tdclatl/QueryBase.cpp +206 -127
- data/source/global/tdclatl/QueryBase.h +55 -59
- data/source/global/tdclatl/Record.cpp +214 -0
- data/source/global/tdclatl/Record.h +96 -0
- data/source/global/tdclatl/Recordset.cpp +278 -0
- data/source/global/tdclatl/Recordset.h +83 -0
- data/source/global/tdclatl/RecordsetQuery.cpp +118 -0
- data/source/global/tdclatl/RecordsetQuery.h +126 -0
- data/source/global/tdclatl/Table.cpp +57 -60
- data/source/global/tdclatl/Table.h +32 -29
- data/source/global/tdclatl/TableDef.cpp +63 -62
- data/source/global/tdclatl/TableDef.h +20 -22
- data/source/global/tdclatl/TdVersion.cpp +3 -3
- data/source/global/tdclatl/TdVersion.h +15 -11
- data/source/global/tdclatl/_IDatabaseEvents_CP.h +99 -92
- data/source/global/tdclatl/activeTable.cpp +355 -0
- data/source/global/tdclatl/activeTable.h +79 -0
- data/source/global/tdclatl/dllmain.cpp +4 -3
- data/source/global/tdclatl/dllmain.h +7 -6
- data/source/global/tdclatl/keySegment.h +22 -18
- data/source/global/tdclatl/resource.h +0 -0
- data/source/global/tdclatl/stdafx.h +6 -4
- data/source/global/tdclatl/targetver.h +0 -1
- data/source/global/tdclatl/tdclatl.cpp +10 -5
- data/source/global/tdclatl/tdclatl.idl +530 -14
- data/source/linux/charsetConvert.h +78 -79
- data/source/linux/linuxTypes.h +9 -12
- data/source/linux/tchar.h +168 -166
- data/transactd.gemspec +24 -16
- metadata +98 -12
- data/bin/common/tdclc_32_1_2.dll +0 -0
- data/bin/common/tdclc_64_1_2.dll +0 -0
- data/build/tdclc/tdclc_32.cbproj +0 -173
- data/build/tdclcpp/tdclcpp_bcb_32.cbproj +0 -232
- data/build/tdclrb/GEM_VERSION +0 -3
- data/source/bzs/db/protocol/tdap/client/filter.cpp +0 -43
- data/source/bzs/example/useORM.cpp +0 -585
|
@@ -0,0 +1,818 @@
|
|
|
1
|
+
/*=================================================================
|
|
2
|
+
Copyright (C) 2014 BizStation Corp All rights reserved.
|
|
3
|
+
|
|
4
|
+
This program is free software; you can redistribute it and/or
|
|
5
|
+
modify it under the terms of the GNU General Public License
|
|
6
|
+
as published by the Free Software Foundation; either version 2
|
|
7
|
+
of the License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License
|
|
15
|
+
along with this program; if not, write to the Free Software
|
|
16
|
+
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
17
|
+
02111-1307, USA.
|
|
18
|
+
=================================================================*/
|
|
19
|
+
#pragma hdrstop
|
|
20
|
+
#include "groupQuery.h"
|
|
21
|
+
#include "recordsetImple.h"
|
|
22
|
+
#include <boost/algorithm/string.hpp>
|
|
23
|
+
|
|
24
|
+
#pragma package(smart_init)
|
|
25
|
+
|
|
26
|
+
namespace bzs
|
|
27
|
+
{
|
|
28
|
+
namespace db
|
|
29
|
+
{
|
|
30
|
+
namespace protocol
|
|
31
|
+
{
|
|
32
|
+
namespace tdap
|
|
33
|
+
{
|
|
34
|
+
namespace client
|
|
35
|
+
{
|
|
36
|
+
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// struct fieldNamesImple
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
struct fieldNamesImple
|
|
41
|
+
{
|
|
42
|
+
std::vector<std::_tstring> keyFields;
|
|
43
|
+
fieldNamesImple() {}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// class fieldNames
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
fieldNames* fieldNames::create()
|
|
51
|
+
{
|
|
52
|
+
return new fieldNames();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
void fieldNames::release()
|
|
56
|
+
{
|
|
57
|
+
delete this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
fieldNames::fieldNames() : m_impl(new fieldNamesImple)
|
|
61
|
+
{
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fieldNames::fieldNames(const fieldNames& r)
|
|
65
|
+
: m_impl(new fieldNamesImple(*r.m_impl))
|
|
66
|
+
{
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
fieldNames& fieldNames::operator=(const fieldNames& r)
|
|
70
|
+
{
|
|
71
|
+
if (this != &r)
|
|
72
|
+
{
|
|
73
|
+
*m_impl = *r.m_impl;
|
|
74
|
+
}
|
|
75
|
+
return *this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
fieldNames::~fieldNames()
|
|
79
|
+
{
|
|
80
|
+
delete m_impl;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
fieldNames& fieldNames::reset()
|
|
84
|
+
{
|
|
85
|
+
m_impl->keyFields.clear();
|
|
86
|
+
return *this;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fieldNames& fieldNames::keyField(const _TCHAR* name, const _TCHAR* name1,
|
|
90
|
+
const _TCHAR* name2, const _TCHAR* name3,
|
|
91
|
+
const _TCHAR* name4, const _TCHAR* name5,
|
|
92
|
+
const _TCHAR* name6, const _TCHAR* name7,
|
|
93
|
+
const _TCHAR* name8, const _TCHAR* name9,
|
|
94
|
+
const _TCHAR* name10)
|
|
95
|
+
{
|
|
96
|
+
m_impl->keyFields.clear();
|
|
97
|
+
if (name)
|
|
98
|
+
m_impl->keyFields.push_back(name);
|
|
99
|
+
if (name1)
|
|
100
|
+
m_impl->keyFields.push_back(name1);
|
|
101
|
+
if (name2)
|
|
102
|
+
m_impl->keyFields.push_back(name2);
|
|
103
|
+
if (name3)
|
|
104
|
+
m_impl->keyFields.push_back(name3);
|
|
105
|
+
if (name4)
|
|
106
|
+
m_impl->keyFields.push_back(name4);
|
|
107
|
+
if (name5)
|
|
108
|
+
m_impl->keyFields.push_back(name5);
|
|
109
|
+
if (name6)
|
|
110
|
+
m_impl->keyFields.push_back(name6);
|
|
111
|
+
if (name7)
|
|
112
|
+
m_impl->keyFields.push_back(name7);
|
|
113
|
+
if (name8)
|
|
114
|
+
m_impl->keyFields.push_back(name8);
|
|
115
|
+
if (name9)
|
|
116
|
+
m_impl->keyFields.push_back(name9);
|
|
117
|
+
if (name10)
|
|
118
|
+
m_impl->keyFields.push_back(name10);
|
|
119
|
+
return *this;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
int fieldNames::count() const
|
|
123
|
+
{
|
|
124
|
+
return (int)m_impl->keyFields.size();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const _TCHAR* fieldNames::getValue(int index) const
|
|
128
|
+
{
|
|
129
|
+
assert(index >= 0 && index < count());
|
|
130
|
+
return m_impl->keyFields[index].c_str();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const _TCHAR* fieldNames::operator[](int index) const
|
|
134
|
+
{
|
|
135
|
+
assert(index >= 0 && index < count());
|
|
136
|
+
return m_impl->keyFields[index].c_str();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
void fieldNames::addValue(const _TCHAR* v)
|
|
140
|
+
{
|
|
141
|
+
m_impl->keyFields.push_back(v);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
void fieldNames::addValues(const _TCHAR* values, const _TCHAR* delmi)
|
|
145
|
+
{
|
|
146
|
+
boost::algorithm::split(m_impl->keyFields, values, boost::is_any_of(delmi));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ---------------------------------------------------------------------------
|
|
150
|
+
// struct recordsetQueryImple
|
|
151
|
+
// ---------------------------------------------------------------------------
|
|
152
|
+
struct recordsetQueryImple
|
|
153
|
+
{
|
|
154
|
+
row_ptr row;
|
|
155
|
+
std::vector<unsigned char> compType;
|
|
156
|
+
std::vector<short> indexes;
|
|
157
|
+
std::vector<char> combine;
|
|
158
|
+
short endIndex;
|
|
159
|
+
fielddefs compFields;
|
|
160
|
+
recordsetQueryImple() {}
|
|
161
|
+
recordsetQueryImple(const recordsetQueryImple& r)
|
|
162
|
+
: row(r.row), compType(r.compType), indexes(r.indexes),
|
|
163
|
+
combine(r.combine), endIndex(r.endIndex), compFields(r.compFields)
|
|
164
|
+
{
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// ---------------------------------------------------------------------------
|
|
169
|
+
// class recordsetQuery
|
|
170
|
+
// ---------------------------------------------------------------------------
|
|
171
|
+
|
|
172
|
+
recordsetQuery* recordsetQuery::create()
|
|
173
|
+
{
|
|
174
|
+
return new recordsetQuery();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
void recordsetQuery::release()
|
|
178
|
+
{
|
|
179
|
+
delete this;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
recordsetQuery::recordsetQuery() : query(), m_imple(new recordsetQueryImple)
|
|
183
|
+
{
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
recordsetQuery::recordsetQuery(const recordsetQuery& r)
|
|
187
|
+
: query(r), m_imple(new recordsetQueryImple(*r.m_imple))
|
|
188
|
+
{
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
recordsetQuery& recordsetQuery::operator=(const recordsetQuery& r)
|
|
192
|
+
{
|
|
193
|
+
if (this != &r)
|
|
194
|
+
{
|
|
195
|
+
query::operator=(r);
|
|
196
|
+
*m_imple = *r.m_imple;
|
|
197
|
+
}
|
|
198
|
+
return *this;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
recordsetQuery::~recordsetQuery()
|
|
202
|
+
{
|
|
203
|
+
delete m_imple;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
void recordsetQuery::init(const fielddefs* fdinfo)
|
|
207
|
+
{
|
|
208
|
+
const std::vector<std::_tstring>& tokns = getWheres();
|
|
209
|
+
m_imple->indexes.clear();
|
|
210
|
+
m_imple->compFields.clear();
|
|
211
|
+
for (int i = 0; i < (int)tokns.size(); i += 4)
|
|
212
|
+
{
|
|
213
|
+
int index = fdinfo->indexByName(tokns[i].c_str());
|
|
214
|
+
m_imple->indexes.push_back(index);
|
|
215
|
+
m_imple->compFields.push_back(&((*fdinfo)[index]), true /*rePosition*/);
|
|
216
|
+
}
|
|
217
|
+
memoryRecord* mr = memoryRecord::create(m_imple->compFields);
|
|
218
|
+
mr->setRecordData(0, 0, &m_imple->endIndex, true);
|
|
219
|
+
m_imple->row.reset(mr);
|
|
220
|
+
|
|
221
|
+
int index = 0;
|
|
222
|
+
for (int i = 0; i < (int)tokns.size(); i += 4)
|
|
223
|
+
{
|
|
224
|
+
field fd = (*m_imple->row)[index];
|
|
225
|
+
fd = tokns[i + 2].c_str();
|
|
226
|
+
bool part = fd.isCompPartAndMakeValue();
|
|
227
|
+
unsigned char ct = getFilterLogicTypeCode(tokns[i + 1].c_str());
|
|
228
|
+
if (!part)
|
|
229
|
+
ct |= CMPLOGICAL_VAR_COMP_ALL;
|
|
230
|
+
|
|
231
|
+
m_imple->compType.push_back(ct);
|
|
232
|
+
if (i + 3 < (int)tokns.size())
|
|
233
|
+
{
|
|
234
|
+
std::_tstring s = tokns[i + 3];
|
|
235
|
+
if (s == _T("or"))
|
|
236
|
+
m_imple->combine.push_back(eCor);
|
|
237
|
+
else if (s == _T("and"))
|
|
238
|
+
m_imple->combine.push_back(eCand);
|
|
239
|
+
}
|
|
240
|
+
else
|
|
241
|
+
m_imple->combine.push_back(eCend);
|
|
242
|
+
++index;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
bool recordsetQuery::isMatch(int ret, unsigned char compType) const
|
|
247
|
+
{
|
|
248
|
+
compType &= 0xf; // lower then 15
|
|
249
|
+
switch ((eCompType)compType)
|
|
250
|
+
{
|
|
251
|
+
case eEqual:
|
|
252
|
+
return (ret == 0);
|
|
253
|
+
case eGreaterEq:
|
|
254
|
+
return (ret >= 0);
|
|
255
|
+
case eLessEq:
|
|
256
|
+
return (ret <= 0);
|
|
257
|
+
case eGreater:
|
|
258
|
+
return (ret > 0);
|
|
259
|
+
case eLess:
|
|
260
|
+
return (ret < 0);
|
|
261
|
+
case eNotEq:
|
|
262
|
+
return (ret != 0);
|
|
263
|
+
}
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
bool recordsetQuery::match(const row_ptr row) const
|
|
268
|
+
{
|
|
269
|
+
for (int i = 0; i < (int)m_imple->indexes.size(); ++i)
|
|
270
|
+
{
|
|
271
|
+
short index = m_imple->indexes[i];
|
|
272
|
+
bool ret = isMatch(
|
|
273
|
+
(*row)[index].comp((*m_imple->row)[i], m_imple->compType[i]),
|
|
274
|
+
m_imple->compType[i]);
|
|
275
|
+
if (m_imple->combine[i] == eCend)
|
|
276
|
+
return ret;
|
|
277
|
+
if (ret && m_imple->combine[i] == eCor)
|
|
278
|
+
return true;
|
|
279
|
+
if (!ret && m_imple->combine[i] == eCand)
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
assert(0);
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
inline void setValue(row_ptr& row, int key, double value)
|
|
287
|
+
{
|
|
288
|
+
(*row)[key] = value;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// ---------------------------------------------------------------------------
|
|
292
|
+
// class groupQueryImple
|
|
293
|
+
// ---------------------------------------------------------------------------
|
|
294
|
+
class groupQueryImple : public fieldNames
|
|
295
|
+
{
|
|
296
|
+
// not delete by destructor. simple copy is ok;
|
|
297
|
+
std::vector<groupFuncBase*> m_funcs;
|
|
298
|
+
|
|
299
|
+
void removeFields(recordsetImple& mdls)
|
|
300
|
+
{
|
|
301
|
+
const fielddefs& fds = *mdls.fieldDefs();
|
|
302
|
+
for (int i = (int)fds.size() - 1; i >= 0; --i)
|
|
303
|
+
{
|
|
304
|
+
bool enabled = false;
|
|
305
|
+
for (int j = 0; j < (int)m_impl->keyFields.size(); ++j)
|
|
306
|
+
{
|
|
307
|
+
if (m_impl->keyFields[j] == fds[i].name())
|
|
308
|
+
{
|
|
309
|
+
enabled = true;
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (!enabled)
|
|
314
|
+
{
|
|
315
|
+
for (int j = 0; j < (int)m_funcs.size(); ++j)
|
|
316
|
+
{
|
|
317
|
+
if (!enabled && (m_funcs[j]->resultKey() == i))
|
|
318
|
+
{
|
|
319
|
+
enabled = true;
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (!enabled)
|
|
326
|
+
mdls.removeField(i);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
public:
|
|
331
|
+
groupQueryImple() : fieldNames() {}
|
|
332
|
+
|
|
333
|
+
fieldNames& reset()
|
|
334
|
+
{
|
|
335
|
+
m_funcs.clear();
|
|
336
|
+
return fieldNames::reset();
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
void addFunction(groupFuncBase* func) { m_funcs.push_back(func); }
|
|
340
|
+
|
|
341
|
+
void grouping(recordsetImple& mdls)
|
|
342
|
+
{
|
|
343
|
+
std::vector<recordsetImple::key_type> keyFields;
|
|
344
|
+
|
|
345
|
+
for (int i = 0; i < (int)m_impl->keyFields.size(); ++i)
|
|
346
|
+
keyFields.push_back(resolvKeyValue(mdls, m_impl->keyFields[i]));
|
|
347
|
+
|
|
348
|
+
for (int i = 0; i < (int)m_funcs.size(); ++i)
|
|
349
|
+
{
|
|
350
|
+
|
|
351
|
+
groupFuncBase* f = m_funcs[i];
|
|
352
|
+
f->init(mdls.fieldDefs());
|
|
353
|
+
|
|
354
|
+
if (f->resultKey() == (int)mdls.fieldDefs()->size())
|
|
355
|
+
{
|
|
356
|
+
groupFuncBase::value_type dummy = 0;
|
|
357
|
+
mdls.appendField(f->resultName(), getFieldType(dummy),
|
|
358
|
+
sizeof(dummy));
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
grouping_comp<recordsetImple> groupingComp(mdls, keyFields);
|
|
363
|
+
std::vector<int> index;
|
|
364
|
+
recordsetImple::iterator it = begin(mdls), ite = end(mdls);
|
|
365
|
+
|
|
366
|
+
int i, n = 0;
|
|
367
|
+
while (it != ite)
|
|
368
|
+
{
|
|
369
|
+
bool found = false;
|
|
370
|
+
i = binary_search(n, index, 0, (int)index.size(), groupingComp,
|
|
371
|
+
found);
|
|
372
|
+
if (!found)
|
|
373
|
+
index.insert(index.begin() + i, n);
|
|
374
|
+
for (int j = 0; j < (int)m_funcs.size(); ++j)
|
|
375
|
+
(*m_funcs[j])(*it, i, !found);
|
|
376
|
+
++n;
|
|
377
|
+
++it;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// real sort by index
|
|
381
|
+
recordsetImple c(mdls);
|
|
382
|
+
|
|
383
|
+
clear(mdls);
|
|
384
|
+
for (int i = 0; i < (int)index.size(); ++i)
|
|
385
|
+
{
|
|
386
|
+
recordsetImple::row_type cur = c.getRow(index[i]);
|
|
387
|
+
for (int j = 0; j < (int)m_funcs.size(); ++j)
|
|
388
|
+
setValue(cur, m_funcs[j]->resultKey(), m_funcs[j]->result(i));
|
|
389
|
+
mdls.push_back(cur);
|
|
390
|
+
}
|
|
391
|
+
removeFields(mdls);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const std::vector<groupFuncBase*>& getFunctions() const { return m_funcs; };
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
// ---------------------------------------------------------------------------
|
|
398
|
+
// class groupQuery
|
|
399
|
+
// ---------------------------------------------------------------------------
|
|
400
|
+
groupQuery* groupQuery::create()
|
|
401
|
+
{
|
|
402
|
+
return new groupQuery();
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
void groupQuery::release()
|
|
406
|
+
{
|
|
407
|
+
delete this;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
groupQuery::groupQuery() : m_imple(new groupQueryImple)
|
|
411
|
+
{
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
groupQuery::groupQuery(const groupQuery& r)
|
|
415
|
+
: m_imple(new groupQueryImple(*r.m_imple))
|
|
416
|
+
{
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
groupQuery& groupQuery::operator=(const groupQuery& r)
|
|
420
|
+
{
|
|
421
|
+
if (this != &r)
|
|
422
|
+
{
|
|
423
|
+
*m_imple = *r.m_imple;
|
|
424
|
+
}
|
|
425
|
+
return *this;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
groupQuery::~groupQuery()
|
|
429
|
+
{
|
|
430
|
+
delete m_imple;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
groupQuery& groupQuery::reset()
|
|
434
|
+
{
|
|
435
|
+
m_imple->reset();
|
|
436
|
+
return *this;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
groupQuery& groupQuery::addFunction(groupFuncBase* func)
|
|
440
|
+
{
|
|
441
|
+
m_imple->addFunction(func);
|
|
442
|
+
return *this;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
void groupQuery::grouping(recordsetImple& rs)
|
|
446
|
+
{
|
|
447
|
+
m_imple->grouping(rs);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
groupQuery& groupQuery::keyField(const _TCHAR* name, const _TCHAR* name1,
|
|
451
|
+
const _TCHAR* name2, const _TCHAR* name3,
|
|
452
|
+
const _TCHAR* name4, const _TCHAR* name5,
|
|
453
|
+
const _TCHAR* name6, const _TCHAR* name7,
|
|
454
|
+
const _TCHAR* name8, const _TCHAR* name9,
|
|
455
|
+
const _TCHAR* name10)
|
|
456
|
+
{
|
|
457
|
+
m_imple->keyField(name, name1, name2, name3, name4, name5, name6, name7,
|
|
458
|
+
name8, name9, name10);
|
|
459
|
+
return *this;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const fieldNames& groupQuery::getKeyFields() const
|
|
463
|
+
{
|
|
464
|
+
return *m_imple;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const groupFuncBase* groupQuery::getFunction(int index) const
|
|
468
|
+
{
|
|
469
|
+
assert(index >= 0 && index < functionCount());
|
|
470
|
+
return m_imple->getFunctions()[index];
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
int groupQuery::functionCount() const
|
|
474
|
+
{
|
|
475
|
+
return (int)m_imple->getFunctions().size();
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// ---------------------------------------------------------------------------
|
|
479
|
+
// class groupFuncBaseImple
|
|
480
|
+
// ---------------------------------------------------------------------------
|
|
481
|
+
class groupFuncBaseImple
|
|
482
|
+
{
|
|
483
|
+
public:
|
|
484
|
+
typedef double value_type;
|
|
485
|
+
|
|
486
|
+
private:
|
|
487
|
+
friend class groupQueryImple;
|
|
488
|
+
fieldNames m_targetNames;
|
|
489
|
+
std::_tstring m_resultName;
|
|
490
|
+
int m_resultKey;
|
|
491
|
+
std::vector<int> m_targetKeys;
|
|
492
|
+
|
|
493
|
+
public:
|
|
494
|
+
std::vector<value_type> m_values;
|
|
495
|
+
std::vector<__int64> m_counts;
|
|
496
|
+
|
|
497
|
+
inline groupFuncBaseImple(const fieldNames& targetNames,
|
|
498
|
+
const _TCHAR* resultName = NULL)
|
|
499
|
+
{
|
|
500
|
+
m_targetNames = targetNames;
|
|
501
|
+
m_resultName = (m_targetNames.count() &&
|
|
502
|
+
((resultName == NULL) || resultName[0] == 0x00))
|
|
503
|
+
? targetNames[0]
|
|
504
|
+
: resultName;
|
|
505
|
+
m_values.reserve(10);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
inline void initResultVariable(int index)
|
|
509
|
+
{
|
|
510
|
+
std::vector<value_type>::iterator it = m_values.begin();
|
|
511
|
+
if (index)
|
|
512
|
+
it += index;
|
|
513
|
+
m_values.insert(it, 0.0f);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
inline void init(const fielddefs* fdinfo)
|
|
517
|
+
{
|
|
518
|
+
m_targetKeys.clear();
|
|
519
|
+
for (int i = 0; i < m_targetNames.count(); ++i)
|
|
520
|
+
m_targetKeys.push_back((m_targetNames[i][0] != 0x00)
|
|
521
|
+
? fdinfo->indexByName(m_targetNames[i])
|
|
522
|
+
: -1);
|
|
523
|
+
m_resultKey = fdinfo->indexByName(m_resultName);
|
|
524
|
+
if (m_resultKey == -1)
|
|
525
|
+
m_resultKey = (int)fdinfo->size();
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
inline groupFuncBaseImple() { m_values.reserve(10); }
|
|
529
|
+
|
|
530
|
+
inline fieldNames& targetNames() const
|
|
531
|
+
{
|
|
532
|
+
return (fieldNames&)m_targetNames;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
inline const _TCHAR* resultName() const { return m_resultName.c_str(); }
|
|
536
|
+
|
|
537
|
+
inline void setResultName(const _TCHAR* v)
|
|
538
|
+
{
|
|
539
|
+
m_resultName = _T("");
|
|
540
|
+
if (v && v[0])
|
|
541
|
+
m_resultName = v;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
inline int resultKey() const { return m_resultKey; }
|
|
545
|
+
|
|
546
|
+
inline void reset() { m_values.clear(); };
|
|
547
|
+
|
|
548
|
+
inline value_type result(int groupIndex) const
|
|
549
|
+
{
|
|
550
|
+
return m_values[groupIndex];
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
inline int targetKey(size_t index) const
|
|
554
|
+
{
|
|
555
|
+
assert(index < m_targetKeys.size());
|
|
556
|
+
return m_targetKeys[index];
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
inline int targetKeys() const { return (int)m_targetKeys.size(); }
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
// ---------------------------------------------------------------------------
|
|
563
|
+
// class groupFuncBase
|
|
564
|
+
// ---------------------------------------------------------------------------
|
|
565
|
+
groupFuncBase::groupFuncBase() : m_imple(new groupFuncBaseImple())
|
|
566
|
+
{
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
groupFuncBase::groupFuncBase(const fieldNames& targetNames,
|
|
570
|
+
const _TCHAR* resultName)
|
|
571
|
+
: recordsetQuery(), m_imple(new groupFuncBaseImple(targetNames, resultName))
|
|
572
|
+
{
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
groupFuncBase::groupFuncBase(const groupFuncBase& r)
|
|
576
|
+
: recordsetQuery(r), m_imple(new groupFuncBaseImple(*r.m_imple))
|
|
577
|
+
{
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
groupFuncBase& groupFuncBase::operator=(const groupFuncBase& r)
|
|
581
|
+
{
|
|
582
|
+
if (this != &r)
|
|
583
|
+
{
|
|
584
|
+
*m_imple = *r.m_imple;
|
|
585
|
+
recordsetQuery::operator=(r);
|
|
586
|
+
}
|
|
587
|
+
return *this;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
groupFuncBase::~groupFuncBase()
|
|
591
|
+
{
|
|
592
|
+
delete m_imple;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
void groupFuncBase::initResultVariable(int index)
|
|
596
|
+
{
|
|
597
|
+
m_imple->initResultVariable(index);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
void groupFuncBase::doCalc(const row_ptr& row, int groupIndex)
|
|
601
|
+
{
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
void groupFuncBase::init(const fielddefs* fdinfo)
|
|
605
|
+
{
|
|
606
|
+
if (whereTokens() != 0)
|
|
607
|
+
recordsetQuery::init(fdinfo);
|
|
608
|
+
|
|
609
|
+
m_imple->init(fdinfo);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
groupFuncBase& groupFuncBase::operator=(const recordsetQuery& v)
|
|
613
|
+
{
|
|
614
|
+
recordsetQuery::operator=(v);
|
|
615
|
+
return *this;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
fieldNames& groupFuncBase::targetNames() const
|
|
619
|
+
{
|
|
620
|
+
return m_imple->targetNames();
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
const _TCHAR* groupFuncBase::resultName() const
|
|
624
|
+
{
|
|
625
|
+
return m_imple->resultName();
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
void groupFuncBase::setResultName(const _TCHAR* v)
|
|
629
|
+
{
|
|
630
|
+
m_imple->setResultName(v);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
int groupFuncBase::resultKey() const
|
|
634
|
+
{
|
|
635
|
+
return m_imple->resultKey();
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
void groupFuncBase::reset()
|
|
639
|
+
{
|
|
640
|
+
m_imple->reset();
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
void groupFuncBase::operator()(const row_ptr& row, int index, bool insert)
|
|
644
|
+
{
|
|
645
|
+
if (insert)
|
|
646
|
+
initResultVariable(index); // setNullValue
|
|
647
|
+
bool flag = (whereTokens() == 0);
|
|
648
|
+
|
|
649
|
+
if (!flag)
|
|
650
|
+
flag = match(row);
|
|
651
|
+
if (flag)
|
|
652
|
+
doCalc(row, index);
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
groupFuncBase::value_type groupFuncBase::result(int groupIndex) const
|
|
656
|
+
{
|
|
657
|
+
return m_imple->result(groupIndex);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// ---------------------------------------------------------------------------
|
|
661
|
+
// class sum
|
|
662
|
+
// ---------------------------------------------------------------------------
|
|
663
|
+
sum* sum::create(const fieldNames& targetNames, const _TCHAR* resultName)
|
|
664
|
+
{
|
|
665
|
+
return new sum(targetNames, resultName);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
sum::sum(const fieldNames& targetNames, const _TCHAR* resultName)
|
|
669
|
+
: groupFuncBase(targetNames, resultName)
|
|
670
|
+
{
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
void sum::doCalc(const row_ptr& row, int index)
|
|
674
|
+
{
|
|
675
|
+
value_type tmp = 0;
|
|
676
|
+
for (int i = 0; i < m_imple->targetKeys(); ++i)
|
|
677
|
+
m_imple->m_values[index] +=
|
|
678
|
+
fieldValue((*row)[m_imple->targetKey(i)], tmp);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
groupFuncBase* sum::clone()
|
|
682
|
+
{
|
|
683
|
+
groupFuncBase* p = new sum();
|
|
684
|
+
*p = *this;
|
|
685
|
+
return p;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// ---------------------------------------------------------------------------
|
|
689
|
+
// class count
|
|
690
|
+
// ---------------------------------------------------------------------------
|
|
691
|
+
count* count::create(const _TCHAR* resultName)
|
|
692
|
+
{
|
|
693
|
+
return new count(resultName);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
count::count(const _TCHAR* resultName) : groupFuncBase()
|
|
697
|
+
{
|
|
698
|
+
setResultName(resultName);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
void count::doCalc(const row_ptr& row, int index)
|
|
702
|
+
{
|
|
703
|
+
m_imple->m_values[index] = m_imple->m_values[index] + 1;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
groupFuncBase* count::clone()
|
|
707
|
+
{
|
|
708
|
+
groupFuncBase* p = new count();
|
|
709
|
+
*p = *this;
|
|
710
|
+
return p;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// ---------------------------------------------------------------------------
|
|
714
|
+
// class avg
|
|
715
|
+
// ---------------------------------------------------------------------------
|
|
716
|
+
avg* avg::create(const fieldNames& targetNames, const _TCHAR* resultName)
|
|
717
|
+
{
|
|
718
|
+
return new avg(targetNames, resultName);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
avg::avg(const fieldNames& targetNames, const _TCHAR* resultName)
|
|
722
|
+
: sum(targetNames, resultName)
|
|
723
|
+
{
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
void avg::initResultVariable(int index)
|
|
727
|
+
{
|
|
728
|
+
sum::initResultVariable(index);
|
|
729
|
+
m_imple->m_counts.insert(m_imple->m_counts.begin() + index, 0);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
void avg::doCalc(const row_ptr& row, int index)
|
|
733
|
+
{
|
|
734
|
+
sum::doCalc(row, index);
|
|
735
|
+
m_imple->m_counts[index] = m_imple->m_counts[index] + 1;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
avg::value_type avg::result(int index) const
|
|
739
|
+
{
|
|
740
|
+
return m_imple->m_values[index] / m_imple->m_counts[index];
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
groupFuncBase* avg::clone()
|
|
744
|
+
{
|
|
745
|
+
groupFuncBase* p = new avg();
|
|
746
|
+
*p = *this;
|
|
747
|
+
return p;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// ---------------------------------------------------------------------------
|
|
751
|
+
// class min
|
|
752
|
+
// ---------------------------------------------------------------------------
|
|
753
|
+
min* min::create(const fieldNames& targetNames, const _TCHAR* resultName)
|
|
754
|
+
{
|
|
755
|
+
return new min(targetNames, resultName);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
min::min(const fieldNames& targetNames, const _TCHAR* resultName)
|
|
759
|
+
: sum(targetNames, resultName), m_flag(true)
|
|
760
|
+
{
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
void min::doCalc(const row_ptr& row, int index)
|
|
764
|
+
{
|
|
765
|
+
value_type tmp = 0;
|
|
766
|
+
for (int i = 0; i < m_imple->targetKeys(); ++i)
|
|
767
|
+
{
|
|
768
|
+
tmp = fieldValue((*row)[m_imple->targetKey(i)], tmp);
|
|
769
|
+
if (m_flag || m_imple->m_values[index] > tmp)
|
|
770
|
+
m_flag = false;
|
|
771
|
+
m_imple->m_values[index] = tmp;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
groupFuncBase* min::clone()
|
|
776
|
+
{
|
|
777
|
+
groupFuncBase* p = new min();
|
|
778
|
+
*p = *this;
|
|
779
|
+
return p;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// ---------------------------------------------------------------------------
|
|
783
|
+
// class max
|
|
784
|
+
// ---------------------------------------------------------------------------
|
|
785
|
+
max* max::create(const fieldNames& targetNames, const _TCHAR* resultName)
|
|
786
|
+
{
|
|
787
|
+
return new max(targetNames, resultName);
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
max::max(const fieldNames& targetNames, const _TCHAR* resultName)
|
|
791
|
+
: sum(targetNames, resultName), m_flag(true)
|
|
792
|
+
{
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
void max::doCalc(const row_ptr& row, int index)
|
|
796
|
+
{
|
|
797
|
+
value_type tmp = 0;
|
|
798
|
+
for (int i = 0; i < m_imple->targetKeys(); ++i)
|
|
799
|
+
{
|
|
800
|
+
tmp = fieldValue((*row)[m_imple->targetKey(i)], tmp);
|
|
801
|
+
if (m_flag || m_imple->m_values[index] < tmp)
|
|
802
|
+
m_flag = false;
|
|
803
|
+
m_imple->m_values[index] = tmp;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
groupFuncBase* max::clone()
|
|
808
|
+
{
|
|
809
|
+
groupFuncBase* p = new max();
|
|
810
|
+
*p = *this;
|
|
811
|
+
return p;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
} // namespace client
|
|
815
|
+
} // namespace tdap
|
|
816
|
+
} // namespace protocol
|
|
817
|
+
} // namespace db
|
|
818
|
+
} // namespace bzs
|