IGNITE-4597: CPP: Add methods to reset arguments in sql query.

Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/03ed3813
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/03ed3813
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/03ed3813

Branch: refs/heads/ignite-5075
Commit: 03ed3813c51d06653a88162e8822468a66f462ba
Parents: ccaed07
Author: Igor Sapego <isap...@gridgain.com>
Authored: Wed May 17 13:15:06 2017 +0300
Committer: Igor Sapego <isap...@gridgain.com>
Committed: Wed May 17 13:33:40 2017 +0300

----------------------------------------------------------------------
 .../cpp/core-test/src/cache_query_test.cpp      | 22 ++++++++++++++++++++
 .../core/include/ignite/cache/query/query_sql.h |  8 +++++++
 .../ignite/cache/query/query_sql_fields.h       | 10 ++++++++-
 .../query-example/src/query_example.cpp         |  6 +++---
 4 files changed, 42 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/03ed3813/modules/platforms/cpp/core-test/src/cache_query_test.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/core-test/src/cache_query_test.cpp 
b/modules/platforms/cpp/core-test/src/cache_query_test.cpp
index e9c4610..65dcda5 100644
--- a/modules/platforms/cpp/core-test/src/cache_query_test.cpp
+++ b/modules/platforms/cpp/core-test/src/cache_query_test.cpp
@@ -871,6 +871,20 @@ BOOST_AUTO_TEST_CASE(TestSqlQuery)
     cursor = cache.Query(qry);
     CheckSingleGetAllIter(cursor, 1, "A1", 10);
 
+    // Test resetting query arguments.
+    qry.ClearArguments();
+    qry.AddArgument<int>(30);
+    qry.AddArgument<std::string>("A2");
+
+    cursor = cache.Query(qry);
+    CheckSingle(cursor, 2, "A2", 20);
+
+    cursor = cache.Query(qry);
+    CheckSingleGetAll(cursor, 2, "A2", 20);
+
+    cursor = cache.Query(qry);
+    CheckSingleGetAllIter(cursor, 2, "A2", 20);
+
     // Test query returning multiple entries.
     qry = SqlQuery("QueryPerson", "age < 30");
 
@@ -1150,6 +1164,14 @@ BOOST_AUTO_TEST_CASE(TestSqlFieldsQueryBasic)
 
     cursor = cache.Query(qry);
     CheckSingle(cursor, 1, "A1", 10);
+
+    // Test resetting query arguments.
+    qry.ClearArguments();
+    qry.AddArgument<int>(30);
+    qry.AddArgument<std::string>("A2");
+
+    cursor = cache.Query(qry);
+    CheckSingle(cursor, 2, "A2", 20);
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/03ed3813/modules/platforms/cpp/core/include/ignite/cache/query/query_sql.h
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/core/include/ignite/cache/query/query_sql.h 
b/modules/platforms/cpp/core/include/ignite/cache/query/query_sql.h
index 289d70a..d733476 100644
--- a/modules/platforms/cpp/core/include/ignite/cache/query/query_sql.h
+++ b/modules/platforms/cpp/core/include/ignite/cache/query/query_sql.h
@@ -245,6 +245,14 @@ namespace ignite
                 }
 
                 /**
+                 * Remove all added arguments.
+                 */
+                void ClearArguments()
+                {
+                    args.clear();
+                }
+
+                /**
                  * Write query info to the stream.
                  *
                  * @param writer Writer.

http://git-wip-us.apache.org/repos/asf/ignite/blob/03ed3813/modules/platforms/cpp/core/include/ignite/cache/query/query_sql_fields.h
----------------------------------------------------------------------
diff --git 
a/modules/platforms/cpp/core/include/ignite/cache/query/query_sql_fields.h 
b/modules/platforms/cpp/core/include/ignite/cache/query/query_sql_fields.h
index 7c09d85..954cf43 100644
--- a/modules/platforms/cpp/core/include/ignite/cache/query/query_sql_fields.h
+++ b/modules/platforms/cpp/core/include/ignite/cache/query/query_sql_fields.h
@@ -268,6 +268,14 @@ namespace ignite
                 }
 
                 /**
+                 * Remove all added arguments.
+                 */
+                void ClearArguments()
+                {
+                    args.clear();
+                }
+
+                /**
                  * Write query info to the stream.
                  *
                  * @param writer Writer.
@@ -312,4 +320,4 @@ namespace ignite
     }    
 }
 
-#endif //_IGNITE_CACHE_QUERY_QUERY_SQL_FIELDS
\ No newline at end of file
+#endif //_IGNITE_CACHE_QUERY_QUERY_SQL_FIELDS

http://git-wip-us.apache.org/repos/asf/ignite/blob/03ed3813/modules/platforms/cpp/examples/query-example/src/query_example.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/examples/query-example/src/query_example.cpp 
b/modules/platforms/cpp/examples/query-example/src/query_example.cpp
index 9524100..db7437e 100644
--- a/modules/platforms/cpp/examples/query-example/src/query_example.cpp
+++ b/modules/platforms/cpp/examples/query-example/src/query_example.cpp
@@ -77,7 +77,7 @@ void DoSqlQueryWithDistributedJoin()
 
     std::cout << std::endl;
 
-    qry = SqlQuery("Person", joinSql);
+    qry.ClearArguments();
 
     qry.AddArgument<std::string>("Other");
 
@@ -258,7 +258,7 @@ void DoSqlQueryWithJoin()
 
     std::cout << "Following people are 'Other' employees: " << std::endl;
 
-    qry = SqlQuery(PERSON_TYPE, sql);
+    qry.ClearArguments();
 
     qry.AddArgument<std::string>("Other");
 
@@ -302,7 +302,7 @@ void DoSqlQuery()
 
     std::cout << std::endl;
 
-    qry = SqlQuery(PERSON_TYPE, sql);
+    qry.ClearArguments();
 
     // Execute queries for salary range 1000 - 2000.
     std::cout << "People with salaries between 1000 and 2000 (queried with SQL 
query): " << std::endl;

Reply via email to