C++ / Sqlite questions

António Almeida 1 Reputation point
2024-07-27T22:56:22.4566667+00:00

I've created a Visual Studio C++ application for retrieving results from a Sqlite database.

As, on getting those results, I was receiving wrong accented characters, I sucessfully changed that part of my code to static_cast<const wchar_t*>(sqlite3_column_text16(stmt, 1));

But now, if I update a record, from the C++ application, I get again wrong accented characters - I think because Sqlite only accepts UTF8 encoding.

How can I convert the records containing those characters and send to database in order to get them acceptable by Sqlite ?

Second question

Trying to execute multiple statements in one Sqlite query, separated by ";", it only executes the first and second (create a table and insert records from another), ignoring the last two (drop a table and renaming another)

What am I doing wrong ?

Thanks in advance

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,760 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Flaviu_ 1,011 Reputation points
    2024-08-01T13:32:16.67+00:00

    I put here a SQLite example that uses https://github.com/SqliteModernCpp/sqlite_modern_cpp library to populate a CListCtrl, as you wanted.

    #include <sqlite_modern_cpp.h>
    CListCtrl listCtrl;
    // set listCtrl as detail mode and setup 3 columns
    try {
    	sqlite::database db("c:/temp/test.db3", config);
    	for (auto&& row : db << "select age,name,weight from user")
    	{
    		int age; std::string name; double weight;
    		row >> age >> name >> weight;
    		const auto count = listCtrl.GetItemCount();
    		listCtrl.Insert(count, name.c_cstr());
    		listCtrl.SetItemText(count, 1, std::to_string(age));
    		listCtrl.SetItemText(count, 2, std::to_string(weight));
    	}
    }
    catch (const std::exception& e)
    {
    	std::cout << e.what() << std::endl;
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.