1

When I try to execute sql statement in Firebird C Api, I can only use char* sql statements and I can not execute wide characters. How can I use execute() or prepare() with wide characters?

    const char* updstr = "UPDATE Tablo SET TABLOADI='Türkçe karakterler ğüşıç'";
    //const wchar_t* updstr = L"UPDATE Tablo SET TABLOADI='Türkçe karakterler ğüşıç'";

    // attach employee db
    att = prov->attachDatabase(&status, "employee", 0, NULL);

    // start transaction
    tra = att->startTransaction(&status, 0, NULL);

    // prepare statement
    stmt = att->prepare(&status, tra, 0, updstr, SAMPLES_DIALECT, 0);
  • You should be using placeholders. Parse once and only once per program execution. Don't parse inside loops. – Jeff Holt Dec 02 '19 at 13:41
  • Can you give me an example ? – Hüseyin Babuc Dec 02 '19 at 13:42
  • what is the compiler warning/error once you run the snippet? – Soner from The Ottoman Empire Dec 02 '19 at 13:48
  • 2
    Go to http://www.firebirdfaq.org/faq233/, download the c api guide, go to page 86 to see how to form a SQL statement with placeholders (sometimes called bind variables). Then see pages 106-108 for how to bind values for placeholders. – Jeff Holt Dec 02 '19 at 13:49
  • I do not take errors, characters seeming corrupted in database. – Hüseyin Babuc Dec 02 '19 at 13:55
  • 1
    Instead of (presumably) specifying the SQL text in the current code page for your locale (Turkish, I'm assuming), convert the text to UTF8 encoding, and specify the pointer to those bytes when preparing the statement. – Mark Benningfield Dec 02 '19 at 14:37
  • Use parameters, do not put data values into executable SQL code. http://bobby-tables.com /~/ Specify correct charset in you *connection string* when you attach to the database https://firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25-appx06-charsets.html /~/ When copying your textual data into whose binary buffers you pass as parameters, don't forget to convert them into the same charset/codepage, that you passed to Friebird in the `connection string` /~/ make sure the VARCHAR and text BLOB columns of your DB were creates with proper charset too – Arioch 'The Dec 02 '19 at 17:49
  • You may use FlameRobin sources and IB++ sources for the example of how this was implemented in real code. https://devblogs.microsoft.com/oldnewthing/?p=32103 and https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/ – Arioch 'The Dec 02 '19 at 17:49

1 Answers1

2

Problem solved. When I look at my data in database with Flamerobin, connection and database collation is not set to Utf8, so I saw corrupted characters. I set everywhere to utf8, and it works.