Skip to content

Commit c38ddf8

Browse files
committed
feat(db_connect): 添加批量操作的空容器检查
1 parent 611a91d commit c38ddf8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

hikyuu_cpp/hikyuu/utilities/db_connect/DBConnectBase.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ inline void DBConnectBase::batchSave(Container &container, bool autotrans) {
391391

392392
template <class InputIterator>
393393
void DBConnectBase::batchSave(InputIterator first, InputIterator last, bool autotrans) {
394+
size_t count = std::distance(first, last);
395+
HKU_IF_RETURN(count == 0, void());
396+
394397
SQLStatementPtr st = getStatement(InputIterator::value_type::getInsertSQL());
395398
if (autotrans) {
396399
transaction();
@@ -493,6 +496,9 @@ inline void DBConnectBase::batchUpdate(Container &container, bool autotrans) {
493496

494497
template <class InputIterator>
495498
void DBConnectBase::batchUpdate(InputIterator first, InputIterator last, bool autotrans) {
499+
size_t count = std::distance(first, last);
500+
HKU_IF_RETURN(count == 0, void());
501+
496502
SQLStatementPtr st = getStatement(InputIterator::value_type::getUpdateSQL());
497503
if (autotrans) {
498504
transaction();
@@ -586,6 +592,9 @@ inline void DBConnectBase::batchRemove(Container &container, bool autotrans) {
586592

587593
template <class InputIterator>
588594
void DBConnectBase::batchRemove(InputIterator first, InputIterator last, bool autotrans) {
595+
size_t count = std::distance(first, last);
596+
HKU_IF_RETURN(count == 0, void());
597+
589598
if (autotrans) {
590599
transaction();
591600
}

0 commit comments

Comments
 (0)