[sqlite] out of sequence error 2

2011-09-01 Thread NOCaut

How wait for finish query?
while(q1.step()); // or q1.fetch()   this function i not find

CppSQLite3Query q2= db.execQuery(...); 
otherstring = db.execQuery(two); // out of sequence error 
q2.finalize(); 

-- 
View this message in context: 
http://old.nabble.com/out-of-sequence-error-2-tp32377689p32377689.html
Sent from the SQLite mailing list archive at Nabble.com.

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


Re: [sqlite] out of sequence error 2

2011-09-01 Thread Stephan Beal
On Thu, Sep 1, 2011 at 9:10 AM, NOCaut per...@mail.ru wrote:


 How wait for finish query?
 while(q1.step()); // or q1.fetch()   this function i not find


try q1.finalize(), as someone suggested for your previous post.

-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] out of sequence error 2

2011-09-01 Thread NOCaut

i think. problemm from parallel access not i try create mutex  in main
project, than sent mutexHandle to my dll and 
dw = WaitForSingleObject(hMutex, 5000L) ;

Messagebox(0,Lmessage,Lbox,0); // this messaege(0,L,L,0);

if (dw == WAIT_OBJECT_0)
{
CppSQLite3Query q = base.execQuery( tmp );  
result = utf8_to_unicode(q.getStringField( 0 ));

//MessageBoxW(0,result,L,0);
q.finalize();
}

-- 
View this message in context: 
http://old.nabble.com/out-of-sequence-error-2-tp32377689p32378483.html
Sent from the SQLite mailing list archive at Nabble.com.

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


Re: [sqlite] sql function to change multiple links within a DB

2011-09-01 Thread Black, Michael (IS)
sqlite create table questions (answer text);
sqlite insert into questions values('/FAQ/Doctors');
sqlite select * from questions;
/FAQ/Doctors
sqlite select 
ltrim(ltrim(ltrim(answer,'/'),'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'),'/')
 from questions;
Doctors

You need to add whatever chars are valid for your first part of your link -- 
e.g. 01234567890 if appropriate.

The sequence is:
trim the first slash
trim the chars
trim the 2nd slash

Michael D. Black
Senior Scientist
NG Information Systems
Advanced Analytics Directorate




From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on 
behalf of teahou [tea...@gmail.com]
Sent: Wednesday, August 31, 2011 6:37 PM
To: sqlite-users@sqlite.org
Subject: EXT :[sqlite] sql function to change multiple links within a DB



Hello.  I am doing some work on a SQLite table with just over 5000 rows.  One
column holds some html text with links within, and I need to change every
one of  those links to a new format.

A sample link looks like this:

/FAQ/Doctors Doctors

We will call the 'FAQ' portion of the link, the category and the 'Doctors'
portion the Item.

I need to change it this:

Doctors

I would like change all links with one go, but I can't figure out a way to
'wildcard' the category and items.  There are 60 different categories and
thousands of different items.

The closest I have come is to do it in parts, I came up with this:

UPDATE questions SET answer = REPLACE(answer, 'a href=''/FAQ/', 'a
style=text-decoration: underline; color: blue
onclick=Ti.App.fireEvent(''openContent'', {kind: ''FAQ'', find: ' );

As you can see, this just does the first part, and forces me to do each
category individually.

I had thought to use a combination of substr/instr but the link locations
vary, it could be at the beginning of the text, or it could start after 100
characters.

So, any thoughts, ideas or a good tutorial would be greatly appreciated.
Thanks!






--
View this message in context: 
http://old.nabble.com/sql-function-to-change-multiple-links-within-a-DB-tp32376393p32376393.html
Sent from the SQLite mailing list archive at Nabble.com.

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


[sqlite] sqlite3_step causing Segmentation Fault

2011-09-01 Thread Rafael Toledo
Hello! I'm coding a simple method in C++ to insert a tuple in a small
database. The database has a table called 'user', with 3 fields (id -
the primary key, name, and a image).
I mapped these fields in a class - id is an int, name is a std::string
and image is a std::vector of unsigned char. In this point, I'm ok. To
insert this in the database, I write the following method:

bool DatabaseClass::insertAdminUser(User user) {

int rc;
sqlite3_stmt *statement;

// mydb is defined in the private area of the class
rc = sqlite3_open_v2(database.db, mydb, SQLITE_OPEN_READWRITE, NULL);
if (rc != SQLITE_OK) {
sqlite3_close(mydb);
return false;
}

rc = sqlite3_prepare_v2(mydb, INSERT INTO users (name, isadmin,
photo) VALUES (?, 1, ?), -1, statement, NULL);
if (rc != SQLITE_OK) {
sqlite3_finalize(statement);
sqlite3_close(banco);   
return false;
}

int i = 0;
rc = sqlite3_bind_text(statement, ++i, user.getName().c_str(), -1,
SQLITE_TRANSIENT);
if (rc != SQLITE_OK) {
sqlite3_finalize(statement);
sqlite3_close(banco);
return false;
}

rc = sqlite3_bind_blob(statement, ++i, (void*) user.getPhoto()[0],
user.getPhoto().size(), SQLITE_STATIC);
if (rc != SQLITE_OK) {
sqlite3_finalize(statement);
sqlite3_close(banco);
return false;
}

rc = sqlite3_step(statement); // The app crashes here!
if (rc != SQLITE_DONE  rc != SQLITE_ROW) {
sqlite3_finalize(statement);
sqlite3_close(mydb);
return false;
}

sqlite3_finalize(statement);
sqlite3_close(banco);

return true;
}
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] sqlite3_step causing Segmentation Fault

2011-09-01 Thread Igor Tandetnik
Rafael Toledo rafaeldtol...@gmail.com wrote:
 rc = sqlite3_prepare_v2(mydb, INSERT INTO users (name, isadmin,
 photo) VALUES (?, 1, ?), -1, statement, NULL);
 if (rc != SQLITE_OK) {
 sqlite3_finalize(statement);

If prepare fails, statement is never updated. So you are passing garbage to 
sqlite3_finalize. You shouldn't call it at all.

 sqlite3_close(banco);

What's the relationship between variables named banco and mydb? Why are you 
using one in open, but the other in close?

 rc = sqlite3_bind_blob(statement, ++i, (void*) user.getPhoto()[0],

I suspect that should be user.getPhoto()[0]. Rule of thumb: if you can't get 
it to compile without a cast, you are likely doing something wrong. My psychic 
powers tell me that user.getPhoto() returns vectorchar or similar. You then 
take the first byte of that vector, and interpret it as a pointer - which of 
course is a complete nonsense.

 rc = sqlite3_step(statement); // The app crashes here!

This is where SQLite tries to dereference that bogus pointer for the first time.
-- 
Igor Tandetnik

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


Re: [sqlite] sqlite3_step causing Segmentation Fault

2011-09-01 Thread Black, Michael (IS)
I'm guessing you want (user.getPhoto()[0]) or just user.getPhoto()





A pointer...not the first value of your photo.





Michael D. Black

Senior Scientist

NG Information Systems

Advanced Analytics Directorate




From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on 
behalf of Rafael Toledo [rafaeldtol...@gmail.com]
Sent: Wednesday, August 31, 2011 1:31 PM
To: sqlite-users@sqlite.org
Subject: EXT :[sqlite] sqlite3_step causing Segmentation Fault

Hello! I'm coding a simple method in C++ to insert a tuple in a small
database. The database has a table called 'user', with 3 fields (id -
the primary key, name, and a image).
I mapped these fields in a class - id is an int, name is a std::string
and image is a std::vector of unsigned char. In this point, I'm ok. To
insert this in the database, I write the following method:

bool DatabaseClass::insertAdminUser(User user) {

int rc;
sqlite3_stmt *statement;

// mydb is defined in the private area of the class
rc = sqlite3_open_v2(database.db, mydb, SQLITE_OPEN_READWRITE, NULL);
if (rc != SQLITE_OK) {
sqlite3_close(mydb);
return false;
}

rc = sqlite3_prepare_v2(mydb, INSERT INTO users (name, isadmin,
photo) VALUES (?, 1, ?), -1, statement, NULL);
if (rc != SQLITE_OK) {
sqlite3_finalize(statement);
sqlite3_close(banco);
return false;
}

int i = 0;
rc = sqlite3_bind_text(statement, ++i, user.getName().c_str(), -1,
SQLITE_TRANSIENT);
if (rc != SQLITE_OK) {
sqlite3_finalize(statement);
sqlite3_close(banco);
return false;
}

rc = sqlite3_bind_blob(statement, ++i, (void*) user.getPhoto()[0],
user.getPhoto().size(), SQLITE_STATIC);
if (rc != SQLITE_OK) {
sqlite3_finalize(statement);
sqlite3_close(banco);
return false;
}

rc = sqlite3_step(statement); // The app crashes here!
if (rc != SQLITE_DONE  rc != SQLITE_ROW) {
sqlite3_finalize(statement);
sqlite3_close(mydb);
return false;
}

sqlite3_finalize(statement);
sqlite3_close(banco);

return true;
}
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] (no subject)

2011-09-01 Thread Tim Streater
On 31 Aug 2011 at 23:24, Igor Tandetnik itandet...@mvps.org wrote: 

 On 8/31/2011 5:56 PM, Tim Streater wrote:
 In the above, each database is newly created as shown. What I had
 forgotten to do was to create the test table in the second database
 before copying the data. What seems to happen is that, lacking a
 test table in the test2 database, SQLite appears to assume that I
 must mean the test table in the test1 database - it tries to copy
 data from the table into itself and so gets the error above.

 Yes. This is documented behavior - see http://sqlite.org/lang_attach.html.

Thanks for that helpful link. I'm sure I've looked at it before, but didn't 
register all the details of how it works. Now I see there's a way of referring 
to the original database as main, I'll use fully qualified table names wherever 
I have attached databases.

 Is this reasonable behaviour? I might have expected to have a no such table
 error.

 Which part of the documentation might have led you to expect that?

No part :-)

Sorry for the lack of subject line originally BTW.

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


[sqlite] SQLite discovery otD -- ASCII newlines

2011-09-01 Thread Simon Slavin
Putting this here in the hope it comes in useful for someone sometime.

Have a table which has some text fields in it.  For use with an old system the 
text fields had newlines in which were expressed with C escapes: 
'firstline\nsecondline'.  Here's how I fixed it:

UPDATE myTable SET textfield=REPLACE(textfield,'\n',x'0A');

If anyone can see a better way, or wants to note some hidden danger with the 
above, I welcome it.  Including if there's a problem depending on whether the 
field is UTF-8 or UTF-16.

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


Re: [sqlite] SQLite discovery otD -- ASCII newlines

2011-09-01 Thread Jay A. Kreibich
On Thu, Sep 01, 2011 at 02:52:06PM +0100, Simon Slavin scratched on the wall:
 Putting this here in the hope it comes in useful for someone sometime.
 
 Have a table which has some text fields in it.  For use with an old
 system the text fields had newlines in which were expressed with C
 escapes: 'firstline\nsecondline'.  Here's how I fixed it:
 
 UPDATE myTable SET textfield=REPLACE(textfield,'\n',x'0A');
 
 If anyone can see a better way, or wants to note some hidden 
 danger with the above, I welcome it.  Including if there's a
 problem depending on whether the field is UTF-8 or UTF-16.


  If there are other C-style escapes, it will incorrectly deal
  with something like \\n.

   -j


-- 
Jay A. Kreibich  J A Y  @  K R E I B I.C H 

Intelligence is like underwear: it is important that you have it,
 but showing it to the wrong people has the tendency to make them
 feel uncomfortable. -- Angela Johnson
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Unicode Confusion and Database Size

2011-09-01 Thread Mohit Sindhwani

Hi All,

I apologize first if this question has its roots in my partial 
understanding of unicode and the various UTF-encodings.  We're using 
Windows CE and SQLite3 - so far, we have only used ASCII data.  Now, 
we're going to store data in other languages and feel the need to go 
towards unicode in SQLite3.


I understand that the database could be either UTF-8 or UTF-16 - but 
that would apply to the full DB not to a single column, right?  If that 
is the case, would it not make the database larger if we had a lot of 
content that was originally ASCII?


On the other hand, the other language that we are storing seems to 
require 3 bytes in UTF-8.  Given that, it would appear that using UTF-8 
would be a better idea since it will store more efficiently.


In addition, there are a few other questions:
- FTS would work fine on both UTF-8 and UTF-16 databases, right?
- Can we attach two databases that have different encodings?
- When using Wide Strings in Windows CE, is one encoding more preferable 
over the other to minimize conversions?


I already have a database that has a couple of tables that are in UTF-8 
- is there an easy way for me to build a database from this that is UTF-16?


I'm sorry for the many questions - thanks for the help.

Best Regards,
Mohit.
1/9/2011 | 10:24 PM.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Unicode Confusion and Database Size

2011-09-01 Thread Igor Tandetnik

On 9/1/2011 10:24 AM, Mohit Sindhwani wrote:

I understand that the database could be either UTF-8 or UTF-16 - but
that would apply to the full DB not to a single column, right?


Right.


If that
is the case, would it not make the database larger if we had a lot of
content that was originally ASCII?


UTF-8 is a superset of ASCII. Strings that consist entirely of 7-bit 
ASCII characters are represented exactly the same way in ASCII and in 
UTF-8. That's probably what you want to stick with.



On the other hand, the other language that we are storing seems to
require 3 bytes in UTF-8. Given that, it would appear that using UTF-8
would be a better idea since it will store more efficiently.


If you have lots of Chinese (or Japanese or Korean) text to store, then 
UTF-16 might be more compact. For these languages, one character takes 
three bytes in UTF-8 but only two in UTF-16. On the other hand, plain 
ASCII characters take one byte in UTF-8 but still two bytes in UTF-16. 
So if you have a mix of the two, the issue gets murky.



In addition, there are a few other questions:
- FTS would work fine on both UTF-8 and UTF-16 databases, right?


I believe so, but I'm not very familiar with FTS.


- Can we attach two databases that have different encodings?


Yes. SQLite automatically converts between them as needed, in a 
transparent fashion.



- When using Wide Strings in Windows CE, is one encoding more preferable
over the other to minimize conversions?


Native API in Windows uses UTF-16. You can request UTF-16 strings even 
from UTF-8 database - like I said, SQLite converts between them 
transparently. The cost of conversion is likely negligible compared to 
the other costs of maintaining a database. In fact, UTF-8 might win 
simply because it means less data to read from hard drive, even if it 
requires conversion. The only way to be sure is to test and measure.



I already have a database that has a couple of tables that are in UTF-8
- is there an easy way for me to build a database from this that is UTF-16?


Using sqlite3 command line utility, run .dump command on the old 
database. Create a new database. Use PRAGMA encoding to set it to 
UTF-16. Run .import command on it using the dump file from the old one.

--
Igor Tandetnik

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


Re: [sqlite] Unicode Confusion and Database Size

2011-09-01 Thread Mohit Sindhwani

Hi Igor,

On 1/9/2011 11:57 PM, Igor Tandetnik wrote:

On 9/1/2011 10:24 AM, Mohit Sindhwani wrote:

I understand that the database could be either UTF-8 or UTF-16 - but
that would apply to the full DB not to a single column, right?


Right.



*many useful answers snipped*

Thank you very much!! Your answers are perfect to get me started.  I 
have a couple of tables that are going to have the wider characters - it 
may be that we'll end up splitting the text and FTS tables for that 
language into a separate database and just attach it if we need it.


But at least, I can try this out now.

Thanks,
Mohit.


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