Saving ubyte[] zlib data in sqlite and calling it back

classic Classic list List threaded Threaded
8 messages Options
jic
Reply | Threaded
Open this post in threaded view
|

Saving ubyte[] zlib data in sqlite and calling it back

jic

Greetings.

I have this table,

CREATE TABLE Test (login primary key, password);

and I would like to save zlib data using ubyte[] and also call it back in.  I have things like this:
1. To save in SQLite,
    cmd =
    "  UPDATE Test password = " ~ cast(char[])cast(ubyte[])std.zlib.compress(cast(void[])"password") ~
    "        WHERE login = 'test';";

This works, or at least, it saves in SQlite, but when I call it back, it does not.

2. To call it in SQLite,

char[] passWord = cast(char[])cast(ubyte[])std.zlib.uncompress(cast(void[])r[0]["password"]);

where r[0]["password"] is what I just SELECTED from SQlite.  I am getting an UTF8 error.  This is a D program, so, the syntax may not be known to some or all of you.  However, the more realistic SQLite question would be, how can I save ubyte data in SQLite and also call it back.  Thoughts?  Comments?  Jokes? :-)

thanks.

josé

_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Saving ubyte[] zlib data in sqlite and calling it back

Richard Hipp-3
On Mon, Feb 11, 2013 at 1:45 PM, jose isaias cabrera
<[hidden email]>wrote:

>
> Greetings.
>
> I have this table,
>
> CREATE TABLE Test (login primary key, password);
>
> and I would like to save zlib data using ubyte[] and also call it back in.


Are you trying to store zlib-compressed content in the database file, then
read back the original uncompressed content?  If so, then I suggest adding
two application-defined functions compress() and decompress():

    UPDATE test SET password=compress(password) WHERE login='test';

    SELECT decompress(password) FROM test WHERE login='test';

Sample implementations for the compress() and decompress() functions can be
copied from here:

    http://www.fossil-scm.org/fossil/artifact/a59638aa4c0?ln=53-105

The code for registering these application-defined functions with the
SQLite database connection is seen here:

    http://www.fossil-scm.org/fossil/artifact/a59638aa4c0?ln=119-122




>  I have things like this:
> 1. To save in SQLite,
>     cmd =
>     "  UPDATE Test password = " ~
> cast(char[])cast(ubyte[])std.zlib.compress(cast(void[])"password") ~
>     "        WHERE login = 'test';";
>
> This works, or at least, it saves in SQlite, but when I call it back, it
> does not.
>
> 2. To call it in SQLite,
>
> char[] passWord =
> cast(char[])cast(ubyte[])std.zlib.uncompress(cast(void[])r[0]["password"]);
>
> where r[0]["password"] is what I just SELECTED from SQlite.  I am getting
> an UTF8 error.  This is a D program, so, the syntax may not be known to
> some or all of you.  However, the more realistic SQLite question would be,
> how can I save ubyte data in SQLite and also call it back.  Thoughts?
>  Comments?  Jokes? :-)
>
> thanks.
>
> josé
>
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Saving ubyte[] zlib data in sqlite and calling it back

jose isaias cabrera

Richard Hipp wrote...

> On Mon, Feb 11, 2013 at 1:45 PM, jose isaias cabrera
> <[hidden email]>wrote:
>
>>
>> Greetings.
>>
>> I have this table,
>>
>> CREATE TABLE Test (login primary key, password);
>>
>> and I would like to save zlib data using ubyte[] and also call it back
>> in.
>
>
> Are you trying to store zlib-compressed content in the database file, then
> read back the original uncompressed content?  If so, then I suggest adding
> two application-defined functions compress() and decompress():
>
>    UPDATE test SET password=compress(password) WHERE login='test';
>
>    SELECT decompress(password) FROM test WHERE login='test';
>
> Sample implementations for the compress() and decompress() functions can
> be
> copied from here:
>
>    http://www.fossil-scm.org/fossil/artifact/a59638aa4c0?ln=53-105
>
> The code for registering these application-defined functions with the
> SQLite database connection is seen here:
>
>    http://www.fossil-scm.org/fossil/artifact/a59638aa4c0?ln=119-122

Dr. Hipp, I don't care what Kees or Igor say about you.  You're pretty hip.
This is perfect, thanks.

josé

_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
jic
Reply | Threaded
Open this post in threaded view
|

Re: Saving ubyte[] zlib data in sqlite and calling it back

jic
In reply to this post by Richard Hipp-3
Richard Hipp wrote...

> On Mon, Feb 11, 2013 at 1:45 PM, jose isaias cabrera
> <[hidden email]>wrote:
>
>>
>> Greetings.
>>
>> I have this table,
>>
>> CREATE TABLE Test (login primary key, password);
>>
>> and I would like to save zlib data using ubyte[] and also call it back
>> in.
>
>
> Are you trying to store zlib-compressed content in the database file, then
> read back the original uncompressed content?  If so, then I suggest adding
> two application-defined functions compress() and decompress():
>
>    UPDATE test SET password=compress(password) WHERE login='test';
>
>    SELECT decompress(password) FROM test WHERE login='test';
>
> Sample implementations for the compress() and decompress() functions can
> be
> copied from here:
>
>    http://www.fossil-scm.org/fossil/artifact/a59638aa4c0?ln=53-105
>
> The code for registering these application-defined functions with the
> SQLite database connection is seen here:
>
>    http://www.fossil-scm.org/fossil/artifact/a59638aa4c0?ln=119-122

Dr. Hipp, I don't care what Kees or Igor say about you.  You're pretty hip.
This is perfect, thanks.

josé

_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Saving ubyte[] zlib data in sqlite and calling it back

Teg-3
In reply to this post by jic
Hello jose,

I compress/encrypt to a vector, then write the vector as a blob and
reverse. Read the blob as a vector then reverse the process.

Monday, February 11, 2013, 1:45:34 PM, you wrote:


jic> Greetings.

jic> I have this table,

jic> CREATE TABLE Test (login primary key, password);

jic> and I would like to save zlib data using ubyte[] and also call
jic> it back in.  I have things like this:
jic> 1. To save in SQLite,
jic>     cmd =
jic>     "  UPDATE Test password = " ~
jic> cast(char[])cast(ubyte[])std.zlib.compress(cast(void[])"password")
jic>     "        WHERE login = 'test';";

jic> This works, or at least, it saves in SQlite, but when I call it back, it does not.

jic> 2. To call it in SQLite,

jic> char[] passWord =
jic> cast(char[])cast(ubyte[])std.zlib.uncompress(cast(void[])r[0]["password"]);

jic> where r[0]["password"] is what I just SELECTED from SQlite.  I
jic> am getting an UTF8 error.  This is a D program, so, the syntax
jic> may not be known to some or all of you.  However, the more
jic> realistic SQLite question would be, how can I save ubyte data in
jic> SQLite and also call it back.  Thoughts?  Comments?  Jokes? :-)

jic> thanks.

jic> josé

jic> _______________________________________________
jic> sqlite-users mailing list
jic> [hidden email]
jic> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users




--
Best regards,
 Teg                            mailto:[hidden email]

_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
jic
Reply | Threaded
Open this post in threaded view
|

Re: Saving ubyte[] zlib data in sqlite and calling it back

jic
In reply to this post by Richard Hipp-3

"Richard Hipp" wrote...

> On Mon, Feb 11, 2013 at 1:45 PM, jose isaias cabrera wrote:
>
>>
>> Greetings.
>>
>> I have this table,
>>
>> CREATE TABLE Test (login primary key, password);
>>
>> and I would like to save zlib data using ubyte[] and also call it back
>> in.
>
>
> Are you trying to store zlib-compressed content in the database file, then
> read back the original uncompressed content?  If so, then I suggest adding
> two application-defined functions compress() and decompress():
>
>    UPDATE test SET password=compress(password) WHERE login='test';
>
>    SELECT decompress(password) FROM test WHERE login='test';
>
> Sample implementations for the compress() and decompress() functions can
> be
> copied from here:
>
>    http://www.fossil-scm.org/fossil/artifact/a59638aa4c0?ln=53-105
>
> The code for registering these application-defined functions with the
> SQLite database connection is seen here:
>
>    http://www.fossil-scm.org/fossil/artifact/a59638aa4c0?ln=119-122

Dr. Hipp,

have you thought of including these as part of the normal sqlite core
functions?

_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Saving ubyte[] zlib data in sqlite and calling it back

Simon Slavin-3

On 12 Feb 2013, at 1:33am, jose isaias cabrera <[hidden email]> wrote:

> have you thought of including these as part of the normal sqlite core functions?

I feel that zlib has nothing to do with SQL or databases.  It doesn't belong in a database library.

Simon.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
jic
Reply | Threaded
Open this post in threaded view
|

Re: Saving ubyte[] zlib data in sqlite and calling it back

jic

True...

"Simon Slavin" wrote...
>
> On 12 Feb 2013, at 1:33am, jose isaias cabrera <[hidden email]>
> wrote:
>
>> have you thought of including these as part of the normal sqlite core
>> functions?
>
> I feel that zlib has nothing to do with SQL or databases.  It doesn't
> belong in a database library.

Oh yeah, that...

_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users