Re: [sqlite] Create table - Error code: 21

2017-09-21 Thread Papa
The SQLite3 wrapper class and the client class use std::wstring, 
however, the wrapper performs the necessary conversion to 
std::string::data(), before submitting the requests to SQLite3.

Nice of you to notice this provable cause.

Thanks so much for the help.


On 2017-09-21 5:37 PM, Keith Medcalf wrote:

convert->toString

Please check this function to make sure it does what you think it
does.  What happens if you leave it out and process the raw C string
instead ?

You would have to change the string definition to a "normal" ASCII string.

It is currently defined as UCS-2 characters and sqlite_prepare_v2 does not 
accept UCS-2 (2 byte characters), one single-byte ASCII (7-bit of a byte) or 
UTF-8.




___
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


Re: [sqlite] Create table - Error code: 21

2017-09-21 Thread Papa
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; // 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(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& 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& 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


Re: [sqlite] Create table - Error code: 21

2017-09-21 Thread Keith Medcalf
>> convert->toString

>Please check this function to make sure it does what you think it
>does.  What happens if you leave it out and process the raw C string
>instead ?

You would have to change the string definition to a "normal" ASCII string.  

It is currently defined as UCS-2 characters and sqlite_prepare_v2 does not 
accept UCS-2 (2 byte characters), one single-byte ASCII (7-bit of a byte) or 
UTF-8.




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


Re: [sqlite] Create table - Error code: 21

2017-09-21 Thread Papa
Thanks for your help, in regards to your suggestion, here is the actual 
method that makes the call to createTable.


void 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");";

    db->createTable(wapstr);

    } catch (std::shared_ptr& e) {
    throw e;
    }
}

For the time being I'd like to leave the schema as it is, later on I 
will divide it into different tables.

Again, thanks so much for your time.


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


Re: [sqlite] Create table - Error code: 21

2017-09-21 Thread R Smith

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


Re: [sqlite] Create table - Error code: 21

2017-09-21 Thread Kees Nuyt
On Thu, 21 Sep 2017 04:07:36 -0400, 
Papa  wrote:

Just a side-note:

>     wapstr += L"id INT PRIMARY KEY NOT NULL, ";

"INT PRIMARY KEY" is not enough to create an alias for ROWID,
that only happenes with "INTEGER PRIMARY KEY" :

~ $ sqlite3 test.sqlite
SQLite version 3.21.0 2017-08-14 01:33:07
Enter ".help" for usage hints.
sqlite> create table t1 (id INT PRIMARY KEY NOT NULL, tx
TEXT);
sqlite> create table t2 (id INTEGER PRIMARY KEY NOT NULL, tx
TEXT);
sqlite> pragma table_info(t1);
0|id|INT|1||1
1|tx|TEXT|0||0
sqlite> pragma table_info(t2); -- looks the same, but:
0|id|INTEGER|1||1
1|tx|TEXT|0||0
sqlite> insert into t1 (id,tx) values (3,'t1');
sqlite> insert into t2 (id,tx) values (3,'t2');
sqlite> select ROWID,id,tx from t1; -- ROWID not aliased
1|3|t1
sqlite> select ROWID,id,tx from t2; -- aliased as intended.
3|3|t2
sqlite>

I'm afraid I don't have an answer to your original question.

-- 
Regards,
Kees Nuyt
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Create table - Error code: 21

2017-09-21 Thread Simon Slavin


On 21 Sep 2017, at 9:07am, Papa  wrote:

> convert->toString

Please check this function to make sure it does what you think it does.  What 
happens if you leave it out and process the raw C string instead ?

Also check what Clemens wrong.  What happens if you try to close the db 
connection at that point ?  Do you get an error or does it work ?

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


Re: [sqlite] Create table - Error code: 21

2017-09-21 Thread Clemens Ladisch
Papa wrote:
> // *** THE ERROR IS HERE 
> this->rc = ::sqlite3_prepare_v2(db, 
> convert->toString(sql_statement_request).c_str(), -1, _sql_statement, 
> NULL);
> if (this->rc != SQLITE_OK) {
> this->apstr = "Error message from SQLite3 ";
> this->apstr += ::sqlite3_errmsg(db);
>
> Error message from SQLite3 - bad parameter or other API misuse

There must be something wrong with the connection object.  It's probably
not open.


Regards,
Clemens
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Create table - Error code: 21

2017-09-21 Thread Papa

void myClass::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");";
/*
Test shows:
CREATE TABLE Name(id INT PRIMARY KEY NOT NULL, title_name TEXT, 
first_name TEXT, middle_name TEXT, last_name TEXT, unit_number TEXT, 
street_name TEXT, city TEXT, province TEXT, postal_code TEXT, country 
TEXT, country_code1 TEXT, area_code1 TEXT, region_code1 TEXT, number1 
TEXT, country_code2 TEXT, area_code2 TEXT, region_code2 TEXT, number2 
TEXT, country_code3 TEXT, area_code3 TEXT, region_code3 TEXT, number3 
TEXT, country_code4 TEXT, area_code4 TEXT, region_code4 TEXT, number4 
TEXT, email1 TEXT, email2 TEXT);

*/

    db->createTable(wapstr);

    } catch (std::shared_ptr& e) {
    throw e;
    }
}

void jme::SQLite3_RDB::createTable(const std::wstring& stm) {
    // 1) Assign function value to class value
    this->sql_statement_request = stm;
/*
Test shows that sql_statement_request is :
CREATE TABLE Name(id INT PRIMARY KEY NOT NULL, title_name TEXT, 
first_name TEXT, middle_name TEXT, last_name TEXT, unit_number TEXT, 
street_name TEXT, city TEXT, province TEXT, postal_code TEXT, country 
TEXT, country_code1 TEXT, area_code1 TEXT, region_code1 TEXT, number1 
TEXT, country_code2 TEXT, area_code2 TEXT, region_code2 TEXT, number2 
TEXT, country_code3 TEXT, area_code3 TEXT, region_code3 TEXT, number3 
TEXT, country_code4 TEXT, area_code4 TEXT, region_code4 TEXT, number4 
TEXT, email1 TEXT, email2 TEXT);

*/
    // *** THE ERROR IS HERE 
    this->rc = ::sqlite3_prepare_v2(db, 
convert->toString(sql_statement_request).c_str(), -1, 
_sql_statement, NULL);

    if (this->rc != SQLITE_OK) {
    this->apstr = "Error message from SQLite3 ";
    this->apstr += ::sqlite3_errmsg(db);
    this->apstr += "\nError code: ";
    this->apstr += jme::core::to_string(this->rc);
    this->wapex->setException(this->apstr, JMEFILE, JMEMETHOD, 
JMELINE);


    this->finalize();

    throw this->wapex;
    }
    try {
    this->runStep(this->binary_sql_statement);
    } catch (std::shared_ptr& we) {
    throw we;
    }

    // Call finalize to terminate the transaction - The constructor 
closes the db connection.

    this->finalize();
}

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

The source code for SQLite3_RDB is here, should you'd like to see it.
http://arbolone.ca/Testings/sqlite3_rdb01.html
http://arbolone.ca/Testings/sqlite3_rdb02.html

Any help would be most appreciated.

--
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