1. Sid Price
  2. Valentina Database ADK
  3. Donnerstag, September 29 2016, 10:16 PM
  4.  Abonnieren via E-Mail
While the String class has many operators and methods I cannot find binary operators that concatenate Strings with literals, these would be useful for example when building a query string that may have literal parts and parts defined elsewhere in the code.

For example suppose we have a table name defined in a header file:

#define theTableName "tblName"

Then we want to build a query string:

String strQuery = "SELECT * FROM " + theTableName ;

This appears to not be possible with the String class.

Is there a way to do this, or do we have to build queries using the "string" class and then convert them to "String" to use them?

Thanks,
Sid
Kommentar
There are no comments made yet.
Sid Price Akzeptierte Antwort
I forgot to mention that I know we can use the "+=" operator, however this makes for lots of repeated code when building a long query.
Sid
Kommentar
There are no comments made yet.
Sergey Pashkov Akzeptierte Antwort
Hi Sid,

In this case that's not an error from a String class.

"SELECT * FROM " and theTableName are pointers (const char*), so "+" can't be used here.

You can simply write:
String strQuery = "SELECT * FROM " theTableName;

And they are combined at the build time.
Kommentar
There are no comments made yet.
Ruslan Zasukhin Akzeptierte Antwort
that is right.

C++ can do this:

const char* p = "aaaaa" "bbbbb" "ccccc";

result is single string "aaaaabbbbbccccc";

BTW, the same rule works in Valentina SQL (and in SQL standard)
Kommentar
There are no comments made yet.
Sid Price Akzeptierte Antwort
Sergey, Ruslan, thank you for correcting my misunderstanding.
Sid
Kommentar
There are no comments made yet.
  • Seite :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.

Categories

Announcements & News
  1. 0 subcategories
Valentina Studio
  1. 2 subcategories
Valentina Server
  1. 4 subcategories
Valentina Database ADK
  1. 0 subcategories
Valentina Reports ADK
  1. 0 subcategories
Other Discussions
  1. 0 subcategories
BETA Testing
  1. 0 subcategories
Education & Research
  1. 0 subcategories
Omegabundle
  1. 0 subcategories