Sorry, I realized that the example provided in my last email was not as complete as it should have been. I hope the below example would do a better job.

---------

namespace jme{
class Person{
         .....
        std::wstring wapstr; //!< All Purpose Wide String
        // Database
        std::wstring table_name; //<! Default table name
        std::wstring sql_statement; //<! sql statement
        std::unique_ptr<jme::SQLite3_RDB> db;

        // Database
        void CreateOpenDatabase(const std::wstring& );//!< Database name
        void CreateTable(); //!< Table name
}
};
void jme::Person::CreateOpenDatabase(const std::wstring& dbn) {
    this->db = std::make_unique<jme::SQLite3_RDB>(dbn);
}
void jme::Person::CreateTable() {
    try {
        // Name's data
        wapstr = L"CREATE TABLE ";
        wapstr += table_name;
        wapstr += L"(";
        wapstr += L"id INT PRIMARY KEY NOT NULL, ";
        wapstr += L"title_name TEXT, ";
        wapstr += L"first_name TEXT, ";
        wapstr += L"middle_name TEXT, ";
        wapstr += L"last_name TEXT, ";
        // Address data
        wapstr += L"unit_number TEXT, ";
        wapstr += L"street_name TEXT, ";
        wapstr += L"city TEXT, ";
        wapstr += L"province TEXT, ";
        wapstr += L"postal_code TEXT, ";
        wapstr += L"country TEXT, ";
        // Phone1 data
        wapstr += L"country_code1 TEXT, ";
        wapstr += L"area_code1 TEXT, ";
        wapstr += L"region_code1 TEXT, ";
        wapstr += L"number1 TEXT, ";
        // Phone2 data
        wapstr += L"country_code2 TEXT, ";
        wapstr += L"area_code2 TEXT, ";
        wapstr += L"region_code2 TEXT, ";
        wapstr += L"number2 TEXT, ";
        // Phone3 data
        wapstr += L"country_code3 TEXT, ";
        wapstr += L"area_code3 TEXT, ";
        wapstr += L"region_code3 TEXT, ";
        wapstr += L"number3 TEXT, ";
        // Phone4 data
        wapstr += L"country_code4 TEXT, ";
        wapstr += L"area_code4 TEXT, ";
        wapstr += L"region_code4 TEXT, ";
        wapstr += L"number4 TEXT, ";
        // Email1 data
        wapstr += L"email1 TEXT, ";
        // Email2 data
        wapstr += L"email2 TEXT";
        wapstr += L");";

        this->sql_statement = this->wapstr;

        db->createTable(this->sql_statement); // exception received here

        wapstr.clear();
    } catch (std::shared_ptr<jme::WinException>& e) {
        throw e;
    }
}
void jme::Person::WriteToDatabase(const std::wstring& db_name) {
    try {
        this->table_name = L"Name";
        CreateOpenDatabase(db_name);
        if (db->notExist(this->table_name)) {
            this->CreateTable();
        }
    } catch (std::shared_ptr<jme::WinException>& e) {
        throw e;
    }
}

-------

Thanks for the help.


On 2017-09-21 6:29 AM, R Smith wrote:
On 2017/09/21 10:07 AM, Papa wrote:

The code shows what I have done to create a table, but ::sqlite3_prepare_v2 tells me:
---------------------------
Exception
---------------------------
Error message from SQLite3 - bad parameter or other API misuse
Error code: 21

Perhaps show us the entire code, including the actual call to sqlite3_prepare_v2...
That is always better than to just say "I've called it and it says x..."

Perhaps we might notice a typo or other deficiency in the actual code that you've missed, because the process, strings and method you describe should in principle work perfectly, which means if it doesn't, there is either a typo, an api misuse, or a real bug - none of which we can reliably verify without seeing the entire code.

Also, does db->createTable() expect a full table declaration (including the "CREATE TABLE" words and the semi-colon at the end)? Show the code for that too.

When there is a Gremlin hiding somewhere, best is to expose all hiding places.

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

--
ArbolOne.ca
Using Fire Fox and Thunderbird.
ArbolOne is composed of students and volunteers dedicated to providing free 
services to charitable organizations.
ArbolOne on Java Development in progress [ í ]

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to