Re: [sqlite] how to cast utf16 text to int?

2007-12-12 Thread Trevor Talbot
On 12/11/07, Maxim V. Shiyanovsky <[EMAIL PROTECTED]> wrote:

> One more question - is there any way to insert utf-16 string from
> sqlite3.exe?
> As I understand I can't use syntax like this:
> insert into t values (X'31003700', 1);

No; the sqlite3 shell deals only in UTF-8, which is hard to make work
on Windows because the console doesn't have proper support for it.

However, it does perform casts from BLOB to TEXT by treating the blob
as a set of bytes in UTF-8 form, so that could be used as an escape
syntax:

insert into t values(X'3137', 1);

But since these characters are in the ASCII range anyway, you might as
well just enter them as plain text:

insert into t values('17', 1);

(That also explains the "first digit" trouble you were having: null
bytes are not allowed in strings, so the final TEXT form only
contained one character. It was a happy coincidence that you were
using characters from the ASCII range, and UTF-16 in little endian
form as the input bytes.)

> As I wrote in the first letter I need cast from utf-16 text to int.
> In other words I need select like this:
> Select * from t, d where cast(t.value as int) = d.id

With the above in mind, this should work now.

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



RE: [sqlite] how to cast utf16 text to int?

2007-12-11 Thread Maxim V. Shiyanovsky
Sorry again. The problem is solved. I had to read FM :) and use
sqlite3_open16 instead of sqlite3_open.

-Original Message-
From: Maxim V. Shiyanovsky [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 11, 2007 2:34 PM
To: sqlite-users@sqlite.org
Subject: RE: [sqlite] how to cast utf16 text to int?

Sorry, I forgot initial problem.
As I wrote in the first letter I need cast from utf-16 text to int.
In other words I need select like this:
Select * from t, d where cast(t.value as int) = d.id

Assuming t.value is utf-16 presentation of numeric.
This select works fine for one-digit value. It would be more correct to
say that cast use first utf-16 symbol only.

One more time:

sqlite> create table t (value text, field_type int);
sqlite> create table d (id int, data int);
sqlite> insert into t values (X'31003700', 1);
sqlite> insert into d values (1, 1);
sqlite> insert into d values (17, 2);
sqlite> Select * from t, d where cast(t.value as int) = d.id;
1|1|1|1
sqlite>

So should I use other cast? Is this possible at all?


-
To unsubscribe, send email to [EMAIL PROTECTED]

-


-
To unsubscribe, send email to [EMAIL PROTECTED]
-



RE: [sqlite] how to cast utf16 text to int?

2007-12-11 Thread Maxim V. Shiyanovsky
Sorry, I forgot initial problem.
As I wrote in the first letter I need cast from utf-16 text to int.
In other words I need select like this:
Select * from t, d where cast(t.value as int) = d.id

Assuming t.value is utf-16 presentation of numeric.
This select works fine for one-digit value. It would be more correct to
say that cast use first utf-16 symbol only.

One more time:

sqlite> create table t (value text, field_type int);
sqlite> create table d (id int, data int);
sqlite> insert into t values (X'31003700', 1);
sqlite> insert into d values (1, 1);
sqlite> insert into d values (17, 2);
sqlite> Select * from t, d where cast(t.value as int) = d.id;
1|1|1|1
sqlite>

So should I use other cast? Is this possible at all?

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



RE: [sqlite] how to cast utf16 text to int?

2007-12-11 Thread Maxim V. Shiyanovsky
Thanks, Trevor.
I'll try it.
One more question - is there any way to insert utf-16 string from
sqlite3.exe?
As I understand I can't use syntax like this:
insert into t values (X'31003700', 1);

-Original Message-
From: Trevor Talbot [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 11, 2007 10:42 AM
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] how to cast utf16 text to int?

On 12/5/07, Maxim V. Shiyanovsky <[EMAIL PROTECTED]> wrote:

> I have table that holds values of different types in utf16.
> I also know value type for the current row.
> How should I cast value to compare it with integer?
>
> This test shows 1 instead of 17 that I expected.
>
> sqlite> create table t (value text, field_type int);
> sqlite> insert into t values (X'31003700', 1);
> sqlite> select value from t;
> 1

Based on your description, I think you mean you're trying to store a
string of Unicode characters, and you're just working with them as
UTF-16 in your application.

In that case, the problem is that you're trying to use blobs. Use text
instead. sqlite3_bind_text16() will let you use UTF-16 in your
application, and SQLite will take care of the on-disk encoding and
byte order.


-
To unsubscribe, send email to [EMAIL PROTECTED]

-


-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] how to cast utf16 text to int?

2007-12-10 Thread Trevor Talbot
On 12/5/07, Maxim V. Shiyanovsky <[EMAIL PROTECTED]> wrote:

> I have table that holds values of different types in utf16.
> I also know value type for the current row.
> How should I cast value to compare it with integer?
>
> This test shows 1 instead of 17 that I expected.
>
> sqlite> create table t (value text, field_type int);
> sqlite> insert into t values (X'31003700', 1);
> sqlite> select value from t;
> 1

Based on your description, I think you mean you're trying to store a
string of Unicode characters, and you're just working with them as
UTF-16 in your application.

In that case, the problem is that you're trying to use blobs. Use text
instead. sqlite3_bind_text16() will let you use UTF-16 in your
application, and SQLite will take care of the on-disk encoding and
byte order.

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] how to cast utf16 text to int?

2007-12-05 Thread Maxim V. Shiyanovsky
I have table that holds values of different types in utf16.
I also know value type for the current row.
How should I cast value to compare it with integer?

This test shows 1 instead of 17 that I expected.

sqlite> create table t (value text, field_type int);
sqlite> insert into t values (X'31003700', 1);
sqlite> select value from t;
1
sqlite>


I know that sqlite3.exe does not support Unicode but problem persist in
api call also.

If I use this query:
select count(1) as num from t where type = 1 and value = ?
and bind MBC buffer with sqlite3_bind_blob it works fine for value =
3100 (i.e. 1) but return no data when value consists of more than one
digit.

-
To unsubscribe, send email to [EMAIL PROTECTED]
-