{"action":"created","issue":{"url":"https://api.github.com/repos/SOCI/soci/issues/354","labels_url":"https://api.github.com/repos/SOCI/soci/issues/354/labels{/name}","comments_url":"https://api.github.com/repos/SOCI/soci/issues/354/comments","events_url":"https://api.github.com/repos/SOCI/soci/issues/354/events","html_url":"https://github.com/SOCI/soci/issues/354","id":91124087,"number":354,"title":"How to pass dynamic multiple variables to query","user":{"login":"redboltz","id":275959,"avatar_url":"https://avatars.githubusercontent.com/u/275959?v=3","gravatar_id":"","url":"https://api.github.com/users/redboltz","html_url":"https://github.com/redboltz","followers_url":"https://api.github.com/users/redboltz/followers","following_url":"https://api.github.com/users/redboltz/following{/other_user}","gists_url":"https://api.github.com/users/redboltz/gists{/gist_id}","starred_url":"https://api.github.com/users/redboltz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/redboltz/subscriptions","organizations_url":"https://api.github.com/users/redboltz/orgs","repos_url":"https://api.github.com/users/redboltz/repos","events_url":"https://api.github.com/users/redboltz/events{/privacy}","received_events_url":"https://api.github.com/users/redboltz/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/SOCI/soci/labels/Category/Question","name":"Category/Question","color":"bfe5bf"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-06-26T01:48:21Z","updated_at":"2015-06-26T12:34:55Z","closed_at":null,"body":"I'm looking for a way to pass multiple variables as query parameters dynamically.\r\n\r\n```C++\r\nstd::vector<std::string> vs;\r\nvs.push_back(\"key1\");\r\nvs.push_back(\"key2\");\r\nsql << \"select * from mytable as t where t.field1 = :f1 and t.field2 = :f2\", use(vs[0]), use(vs[1]);\r\n```\r\nI can pass the vector of string, vs, individually. My situation is the query string is generated dynamically. For example, comparison fields increase dynamically as follows:\r\n\r\nselect * from mytable as t where t.field1 = :f1 and t.field2 = :f2 and t.field3 = :f3 ...\r\n\r\nHowever, I can't increase use() function dynamically. 'dynamically' means on run time.\r\n\r\nI've tried to pass the vector of strings directly. It compiles but doesn't work. It seems that soci regards 'vs' to the parameter for bulk insertion.\r\n\r\n```C++\r\nsql << \"select * from mytable as t where t.field1 = :f1 and t.field2 = :f2\", use(vs);\r\n```\r\n\r\nI can concatenate query string that contains parameters using string manipulation or query transformation http://soci.sourceforge.net/doc/3.2/queries.html. However, it doesn't provide the way to avoid SQL injection. \r\n\r\nI also checked \"Extending SOCI to support custom (user-defined) C++ types\" http://soci.sourceforge.net/doc/3.2/exchange.html. However, I couldn't find a way to map user defined type, in this case std::vector<std::string> to multiple placeholders.\r\n\r\nIs there any good way to do that?\r\n\r\nI've posted it on the stack-overflow:\r\nhttp://stackoverflow.com/questions/31023172/how-to-provide-the-values-corresponding-to-the-placeholders-in-soci\r\n\r\nAfter I posted it, I noticed here.\r\n"},"comment":{"url":"https://api.github.com/repos/SOCI/soci/issues/comments/115662758","html_url":"https://github.com/SOCI/soci/issues/354#issuecomment-115662758","issue_url":"https://api.github.com/repos/SOCI/soci/issues/354","id":115662758,"user":{"login":"mloskot","id":80741,"avatar_url":"https://avatars.githubusercontent.com/u/80741?v=3","gravatar_id":"","url":"https://api.github.com/users/mloskot","html_url":"https://github.com/mloskot","followers_url":"https://api.github.com/users/mloskot/followers","following_url":"https://api.github.com/users/mloskot/following{/other_user}","gists_url":"https://api.github.com/users/mloskot/gists{/gist_id}","starred_url":"https://api.github.com/users/mloskot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mloskot/subscriptions","organizations_url":"https://api.github.com/users/mloskot/orgs","repos_url":"https://api.github.com/users/mloskot/repos","events_url":"https://api.github.com/users/mloskot/events{/privacy}","received_events_url":"https://api.github.com/users/mloskot/received_events","type":"User","site_admin":false},"created_at":"2015-06-26T12:34:55Z","updated_at":"2015-06-26T12:34:55Z","body":"On 26 June 2015 at 14:18, VZ <notifications@github.com> wrote:\n\n> But it might be useful to note that use() is just a syntactic sugar and\n> that you can also call exchange() directly on the statement\n>\nGood point. All the three flavours of public interfaces, sugar, core and\nsimple, are explained here:\n\nhttp://soci.sourceforge.net/doc/3.2/interfaces.html\n"}}