Re: [Cppcms-users] C++DB question regarding "IN"
Brought to you by:
artyom-beilis
From: Martin B. <mar...@gm...> - 2020-07-13 13:25:36
|
Hi Jon, I don't fully get what you are doing but I'm assuming you want to update rows which the user selected previously on the HTML form. Indeed this does sound like a bit of a pain. And I don't know of any cppdb feature that could help here. I'd suggest using prepared statements like this: Start with a std::stringstream with your query and one placeholder UPDATE my_table SET field_1="my val" WHERE id IN (? Next, since you know how many rows N the user selected, append N-1 times another placeholder ,? So you now have your query with N placeholders UPDATE my_table SET field_1="my val" WHERE id IN (?,?,?,? And then finish it with a paren and semicolon and make a prepared statement from it cppdb::statement stmt = session_handle << strsteam.str(); Now put all the row IDs in for (int rid : vector_of_row_ids) stmt << rid; And finally execute it stmt.exec(); Hope I helped at least a little! Martin Am Freitag, den 10.07.2020, 09:48 -0700 schrieb Jon Foster: > I've skimmed over the C++DB docs a couple of times and I don't see > anything > about the best way to build queries using the "in" operator. My use > case is > doing a bulk "UPDATE" command using "in" to target the set of records > I > want by a list of integer IDs. Example query: > > UPDATE my_table SET field_1="my val" WHERE id IN (1,3,9); > > Right now I'm scrubbing strings coming back from an HTML form (via > C++CMS) > and then building them direct into query string. Seems like C++DB > probably > already has better way. It seems to be well thought out. > > TIA - Jon > |