From 39a95f6939417ebc5d8e716ca1664a1da1fc722c Mon Sep 17 00:00:00 2001
From: znone <glyc@sina.com.cn>
Date: Thu, 09 Feb 2017 12:04:19 +0000
Subject: [PATCH] 根据回调函数参数推断绑定的数据类型。

---
 test/TestSqlite.cpp |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/test/TestSqlite.cpp b/test/TestSqlite.cpp
index 04417ba..7ac4ad6 100644
--- a/test/TestSqlite.cpp
+++ b/test/TestSqlite.cpp
@@ -19,6 +19,12 @@
 	{
 		memset(this, 0, sizeof(TestSqliteRecord));
 	}
+
+	void print() const
+	{
+		printf("ID=\"%d\", Name=\"%s\"\n",
+			id, name);
+	}
 };
 
 namespace qtl
@@ -66,11 +72,9 @@
 	try
 	{
 		db.query("select 0, 'hello world'", 
-			std::tuple<int32_t, std::string>(),
 			[](int32_t i, const std::string& str) {
 				printf("0=\"%d\", 'hello world'=\"%s\"\n",
 					i, str.data());
-				return true;
 		});
 	}
 	catch(qtl::sqlite::error& e)
@@ -153,22 +157,21 @@
 
 	try
 	{
-		db.query("select * from test where id=?",
-			id, std::tuple<int, std::string, std::string>(),
-			[](int id, const std::string& name, std::string& create_time) {
+		db.query("select * from test where id=?", id, 
+			[](int id, const std::string& name, const std::string& create_time) {
 				printf("ID=\"%d\", Name=\"%s\", CrateTime=\"%s\"\n",
 					id, name.data(), create_time.data());
-				return true;
 		});
 
-		db.query("select ID, Name, strftime('%s', CreateTime) from test where id=?",
-			id, TestSqliteRecord(),
-			[](TestSqliteRecord& record) {
+		db.query("select ID, Name, strftime('%s', CreateTime) from test where id=?", id, 
+			[](const TestSqliteRecord& record) {
 				time_t t=record.create_time;
 				printf("ID=\"%d\", Name=\"%s\", CrateTime=\"%s\"\n",
 					record.id, record.name, asctime(localtime(&t)));
-				return true;
 		});
+
+		db.query("select * from test where id=?", id,
+			&TestSqliteRecord::print);
 	}
 	catch(qtl::sqlite::error& e)
 	{

--
Gitblit v1.9.3