Qore BulkSqlUtil Module Reference  1.0
 All Classes Namespaces Functions Variables Groups Pages
BulkSqlUtil.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* BulkSqlUtil.qm Copyright 2015 Qore Technologies, sro
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23 */
24 
25 // minimum required Qore version
26 
27 // require type definitions everywhere
28 
29 // enable all warnings
30 
31 // assume local scope for variables, do not use "$" signs
32 
33 // use SqlUtil
34 
35 
36 /* Version History
37  * 2015-08-02 v1.0: David Nichols <david@qore.org>
38  + the initial version of the BulkSqlUtil module
39 */
40 
66 namespace BulkSqlUtil {
69 
119 
120 public:
121  public :
123  const OptionKeys = (
124  "block_size": sprintf("the row block size used for bulk DML / batch operations; default: %y", OptionDefaults.block_size),
125  "info_log": "a call reference / closure for informational logging",
126  );
127 
129  const OptionDefaults = (
130  "block_size": 1000,
131  );
132 
133 public:
134 
135  private :
138 
140  softint block_size;
141 
144 
147 
149  *code info_log;
150 
152  int row_count = 0;
153 
155  string opname;
156 
159 
160 public:
161 
163 
169  constructor(string name, SqlUtil::Table target, *hash opts);
170 
171 
173 
179  constructor(string name, SqlUtil::AbstractTable target, *hash opts);
180 
181 
183 
185  destructor();
186 
187 
189  private init(*hash opts);
190 
191 
193 
227  queueData(hash data);
228 
229 
231 
265  queueData(list l);
266 
267 
269  private setupInitialRowColumns(hash row);
270 
271 
273  private setupInitialRow(hash row);
274 
275 
277 
307  flush();
308 
309 
311  private flushIntern();
312 
313 
315 
345  discard();
346 
347 
349  nothing commit();
350 
351 
353  nothing rollback();
354 
355 
357  string getTableName();
358 
359 
362 
363 
366 
367 
369  int getRowCount();
370 
371 
373  abstract private flushImpl();
374  };
375 
377 
433 
434 public:
435  private :
437  SQLStatement stmt;
438 
440  *code rowcode;
441 
444 
445 public:
446 
448 
456  constructor(SqlUtil::Table target, *hash opts) ;
457 
458 
460 
468  constructor(SqlUtil::AbstractTable target, *hash opts) ;
469 
470 
472 
497  setRowCode(*code rowc);
498 
499 
501  private init(*hash opts);
502 
503 
505  private setupInitialRowColumns(hash row);
506 
507 
509  private setupInitialRow(hash row);
510 
511 
512  private setupStaticRowValues(reference row);
513 
514 
516 
524  private flushImpl();
525 
526  };
527 
529 
576 
577 public:
578  private :
579  // upsert strategy to use
580  int upsert_strategy;
581  // upsert closure
582  code upsert;
583 
584 public:
585 
587 
593  constructor(SqlUtil::Table target, *hash opts) ;
594 
595 
597 
603  constructor(SqlUtil::AbstractTable target, *hash opts) ;
604 
605 
607  private init(*hash opts);
608 
609 
611  private flushImpl();
612 
613  };
614 };
hash cval
&quot;constant&quot; row values; must be equal in all calls to queueData
Definition: BulkSqlUtil.qm.dox.h:146
*code info_log
an optional info logging callback; must accept a sprintf()-style format specifier and optional argume...
Definition: BulkSqlUtil.qm.dox.h:149
constructor(SqlUtil::Table target, *hash opts)
creates the object from the supplied arguments
private setupInitialRowColumns(hash row)
sets up the block buffer given the initial template hash of lists for inserting
SqlUtil::AbstractTable getTable()
returns the underlying SqlUtil::AbstractTable object
string sprintf(string fmt,...)
private flushIntern()
flushes queued data to the database
constructor(SqlUtil::Table target, *hash opts)
creates the object from the supplied arguments
Qore::SQL::AbstractDatasource getDatasource()
returns the AbstractDatasource object associated with this object
queueData(hash data)
queues row data in the block buffer; the block buffer is flushed to the DB if the buffer size reaches...
discard()
discards any buffered batched data; this method should be called before destroying the object if an e...
int row_count
row count
Definition: BulkSqlUtil.qm.dox.h:152
base class for bulk DML upsert operations
Definition: BulkSqlUtil.qm.dox.h:575
private flushImpl()
inserts internally-queued queued data in the database wuith bulk DML operations
const OptionKeys
option keys for this object
Definition: BulkSqlUtil.qm.dox.h:123
private setupInitialRow(hash row)
sets up the block buffer given the initial template row for inserting
string getTableName()
returns the table name
hash static_ret_expr
hash of &quot;returning&quot; arguments
Definition: BulkSqlUtil.qm.dox.h:443
list list(...)
setRowCode(*code rowc)
sets a closure or call reference that will be called when data has been sent to the database and all ...
private setupInitialRow(hash row)
sets up support for &quot;returning&quot; insert options for any possible rowcode member
SQLStatement stmt
statement for DML
Definition: BulkSqlUtil.qm.dox.h:437
base class for bulk DML insert operations
Definition: BulkSqlUtil.qm.dox.h:432
nothing rollback()
discards any queued data and rolls back the transaction
constructor(string name, SqlUtil::Table target, *hash opts)
creates the object from the supplied arguments
int getRowCount()
returns the affected row count
string opname
operation name
Definition: BulkSqlUtil.qm.dox.h:155
private init(*hash opts)
common constructor initialization
nothing commit()
flushes any queued data and commits the transaction
private init(*hash opts)
common constructor initialization
private flushImpl()
executes bulk DML upserts in the database with internally queued data
SqlUtil::AbstractTable table
the target table object
Definition: BulkSqlUtil.qm.dox.h:137
*code rowcode
per-row Closures or Call References for inserts
Definition: BulkSqlUtil.qm.dox.h:440
private setupInitialRowColumns(hash row)
sets up the block buffer given the initial template hash of lists for inserting
destructor()
throws an exception if there is data pending in the internal row data cache; make sure to call flush(...
const OptionDefaults
default option values
Definition: BulkSqlUtil.qm.dox.h:129
abstract private flushImpl()
flushes queued data to the database
flush()
flushes any remaining batched data to the database; this method should always be called before commit...
base class for bulk DML operations
Definition: BulkSqlUtil.qm.dox.h:118
private init(*hash opts)
common constructor initialization
list ret_args
list of &quot;returning&quot; columns
Definition: BulkSqlUtil.qm.dox.h:158
hash hash(object obj)
hash hbuf
buffer for bulk operations
Definition: BulkSqlUtil.qm.dox.h:143
softint block_size
bulk operation block size
Definition: BulkSqlUtil.qm.dox.h:140