Thanks for that. A QuotedString function will be useful indeed and will add that. In this case my language is B4A, which is similar to the old VB6. Very good and much recommended.
RBS On Fri, Jul 27, 2018 at 11:32 AM, R Smith <ryansmit...@gmail.com> wrote: > On 2018/07/27 11:15 AM, Bart Smissaert wrote: > >> xxx is an identifier. It has no meaning at all in SQL and needs to be >> replaced by the app. >> > > Ok, so your app needs to replace xxx with 'A', 'B', 'C' then? > > Well, that depends on what language your App is? > > For example, assuming the query 'SELECT * FROM table1 WHERE a IN (xxx);' > is in variable q: > > Most languages have some standard function akin to: > str_replace(q, "xxx", "'A', 'B', 'C'"); - if the language uses > double-quotes to quote strings (like VB or PHP), or > str_replace(q, 'xxx', '''A'', ''B'', ''C'''); - if the language uses > single-quotes (like most other). > (I assume you already knew this already and the question is more towards > the next bit, but I'm mentioning it since it was asked, and in case you, or > someone else reading this, did not). > > To get the string 'A', 'B', 'C' into a field in a table (from where you > might query it to replace it with your app as above), that would be: > > INSERT INTO t(SearchStr) VALUES ('''A'', ''B'', ''C'''); > > which is essentially the same as 'A', 'B', 'C' where every single quote is > duplicated and then all of it is enclosed with an added pair of single > quotes. > > Note that if this is a string inside your single-quote string quoting > program language, it has to be escaped again, which essentially repeats the > above process to yield something like: > > sQuery = 'INSERT INTO t(SearchStr) VALUES (''''''A'''', ''''B'''', > ''''C'''''');'; > > Though your programming language should have some form of QuotedStr() > function. If not, this should be easy to translate to your language of > choice: > > function QuotedStr(inputStr) string { > s = inputStr; > for(i = len(s); i > 0; i--) { > if ( s[i] = Char(39) ) { insert(s, i, ''''); } > } > QuotedStr = '''' + s + ''''; > } > > Note that '''' and Char(39) both denote a single single-quote character in > string format in a language that uses single quotes to quote strings. > This could make life easier in that you can simply say something like: > > sQuery = 'INSERT INTO t(SearchStr) VALUES (' + QuotedStr('''A'', ''B'', > ''C''') + ');'; > > or even (if you prefer bloat over obscurity): > > sQuery = 'INSERT INTO t(SearchStr) VALUES (' + QuotedStr( QuotedStr('A') + > ', ' + QuotedStr('B') + ', '+ QuotedStr('C') ) + ');'; > > Hope that makes some sense... > Ryan > > > _______________________________________________ > sqlite-users mailing list > sqlite-users@mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users