Re: [sqlite] Compress function
D. Richard Hipp... You are amazing!!! Thanks a lot for Sqlite and for help me! God save D. Richard Hipp! On Wed, 19 2006 17:44:46 -0400, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: "Cesar David Rodas Maldonado" <[EMAIL PROTECTED]> wrote: > I need a funcion from compress a row with Zlib and I am wondering if SQLite > support or if someone did it and want to share him or her code. > Here some code that might help: /* ** SQL function to compress content into a blob using libz */ static void compressFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ int nIn, nOut; long int nOut2; const unsigned char *inBuf; unsigned char *outBuf; assert( argc==1 ); nIn = sqlite3_value_bytes(argv[0]); inBuf = sqlite3_value_blob(argv[0]); nOut = 13 + nIn + (nIn+999)/1000; outBuf = malloc( nOut+4 ); outBuf[0] = nIn>>24 & 0xff; outBuf[1] = nIn>>16 & 0xff; outBuf[2] = nIn>>8 & 0xff; outBuf[3] = nIn & 0xff; nOut2 = (long int)nOut; compress(&outBuf[4], &nOut2, inBuf, nIn); sqlite3_result_blob(context, outBuf, nOut2+4, free); } /* ** An SQL function to decompress. */ static void uncompressFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ unsigned int nIn, nOut, rc; const unsigned char *inBuf; unsigned char *outBuf; long int nOut2; assert( argc==1 ); nIn = sqlite3_value_bytes(argv[0]); if( nIn<=4 ){ return; } inBuf = sqlite3_value_blob(argv[0]); nOut = (inBuf[0]<<24) + (inBuf[1]<<16) + (inBuf[2]<<8) + inBuf[3]; outBuf = malloc( nOut ); nOut2 = (long int)nOut; rc = uncompress(outBuf, &nOut2, &inBuf[4], nIn); if( rc!=Z_OK ){ free(outBuf); }else{ sqlite3_result_blob(context, outBuf, nOut2, free); } } /* Make the functions above accessible to SQLite as follows: */ sqlite3_create_function(db, "compress", 1, SQLITE_UTF8, 0, compressFunc, 0, 0); sqlite3_create_function(db, "uncompress", 1, SQLITE_UTF8, 0, uncompressFunc, 0, 0); -- D. Richard Hipp <[EMAIL PROTECTED]>
Re: [sqlite] Compress function
"Cesar David Rodas Maldonado" <[EMAIL PROTECTED]> wrote: > I need a funcion from compress a row with Zlib and I am wondering if SQLite > support or if someone did it and want to share him or her code. > Here some code that might help: /* ** SQL function to compress content into a blob using libz */ static void compressFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ int nIn, nOut; long int nOut2; const unsigned char *inBuf; unsigned char *outBuf; assert( argc==1 ); nIn = sqlite3_value_bytes(argv[0]); inBuf = sqlite3_value_blob(argv[0]); nOut = 13 + nIn + (nIn+999)/1000; outBuf = malloc( nOut+4 ); outBuf[0] = nIn>>24 & 0xff; outBuf[1] = nIn>>16 & 0xff; outBuf[2] = nIn>>8 & 0xff; outBuf[3] = nIn & 0xff; nOut2 = (long int)nOut; compress(&outBuf[4], &nOut2, inBuf, nIn); sqlite3_result_blob(context, outBuf, nOut2+4, free); } /* ** An SQL function to decompress. */ static void uncompressFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ unsigned int nIn, nOut, rc; const unsigned char *inBuf; unsigned char *outBuf; long int nOut2; assert( argc==1 ); nIn = sqlite3_value_bytes(argv[0]); if( nIn<=4 ){ return; } inBuf = sqlite3_value_blob(argv[0]); nOut = (inBuf[0]<<24) + (inBuf[1]<<16) + (inBuf[2]<<8) + inBuf[3]; outBuf = malloc( nOut ); nOut2 = (long int)nOut; rc = uncompress(outBuf, &nOut2, &inBuf[4], nIn); if( rc!=Z_OK ){ free(outBuf); }else{ sqlite3_result_blob(context, outBuf, nOut2, free); } } /* Make the functions above accessible to SQLite as follows: */ sqlite3_create_function(db, "compress", 1, SQLITE_UTF8, 0, compressFunc, 0, 0); sqlite3_create_function(db, "uncompress", 1, SQLITE_UTF8, 0, uncompressFunc, 0, 0); -- D. Richard Hipp <[EMAIL PROTECTED]>
Re: [sqlite] Compress function
Cesar David Rodas Maldonado wrote: I compile SQLITE 3 source into my APP, but i will like to use like mysql uses ( the COMPRESS() function into the sql), understand? I understand. Unfortunately I haven't implemented that.
Re: [sqlite] Compress function
I compile SQLITE 3 source into my APP, but i will like to use like mysql uses ( the COMPRESS() function into the sql), understand?
Re: [sqlite] Compress function
Cesar David Rodas Maldonado wrote: I need a funcion from compress a row with Zlib and I am wondering if SQLite support or if someone did it and want to share him or her code. Thanks to all Do you want to have it as an Sqlite function or as a function in your application? In general you just download zlib and compile the library on your machine and use the examples in the zlib release as a template.
Re: [sqlite] Compress function
On 7/19/06, Cesar David Rodas Maldonado <[EMAIL PROTECTED]> wrote: Do you know for how much money? On 7/19/06, Jay Sprenkle <[EMAIL PROTECTED]> wrote: > > The author of Sqlite also sells a version that compresses and encrypts > the database. from this page: http://www.hwaci.com/sw/sqlite/prosupport.html 3.0 Encrypted Databases An enhanced version of SQLite is available (for both versions 2.8 and 3.3) that encrypts its database files to help prevent unauthorized access or modification. The entire database file is encrypted2. To an outside observer, the database file appears to contain white noise. There is nothing2 that identifies the file as an SQLite database. The enhanced SQLite with encryption support can continue to read and write ordinary unencrypted databases without any performance penalty. You can use the ATTACH SQL command to attach an encrypted database to an unencrypted database or to attach an unencrypted database to an encrypted one. The password to a database can be changed at any time, though doing so is an expensive operation roughly comparable to VACUUM. The encryption extension descrypts each page of data as it is read from the disk and reencrypts it as modified versions are written back to the disk. But the primary database file and the rollback journal are encrypted. A very fast encryption algorithm is used, but even so it takes time to do all of that encryption and decryption. So when encryption is enabled, there is about a 50% performance loss. The encrypted database enhancements for SQLite are available in source-code form for a one-time licensing fee of $2000 (US). A technical support contract is also recommended but is not required. There are no per-copy royalties. The one-time fee entitles the licensee to free copies of all future updates to the code. You can purchase a perpetual license to the SQLite Encryption Extension online or call +1.704.948.4565 or write to [EMAIL PROTECTED] for additional information. 4.0 Compressed and Encrypted Read-Only Databases A separate extension is available that allows SQLite to read database files that have been both compressed and encrypted. The amount of compression depends on the kind of data that is stored, of course, but typically is in the 50% to 70% range. Compressed databases are read-only. To create a compressed database, first construct a normal uncompressed database holding the desired data. Then run a special command-line tool (included with the extension) that converts the uncompressed database into a much smaller compressed and encrypted database. Afterwards the compressed database can be read (but not written) using this extension. Compressed databases are useful in products that contain a large fixed data set that needs to be squeezed into the limited memory space of a PDA or other gadget or onto a single CD-ROM or DVD. If an application has both a large fixed data set but also some smaller read/write tables, then the large fixed data set can be stored in a compressed database file and the variable database can be held in a separate uncompressed read/write database. The two databases can be accessed as if they were one using the ATTACH command in SQLite. The compressed database extension is separate from the encrypted database extension described in section 3.0 above. But the two extensions can be used together if desired. The compressed database extension is currently in development. A finished version is expected to be available with the release of SQLite version 3.3.0 in January of 2006. However, beta copies are available immediately for preliminary testing purposes. The compressed database extension for SQLite are available in source-code form for a one-time licensing fee of $2000 (US). A technical support contract is also recommended but is not required. There are no per-copy royalties. The one-time fee entitles the licensee to free copies of all future updates to the code. Call 704.948.4565 or write to [EMAIL PROTECTED] for additional information. 5.0 Custom Modifications Some projects can be best served by a customized version of SQLite with specialized capabilities and/or extensions. For example: * Specialize performance tuning or optimization for a particular class of query * Ports of SQLite to new operating systems or execution environments * Application-specific extensions to the SQL query language * Enhanced security features * Bindings to alternative programming languages You should not have to settle for a proprietary database library that lacks needed features when you can have full source code and unlimited rights to a database that meets your needs exactly and completely. Just let us know what your special requirements are. We can reply with either a fixed-priced bid or give you an estimate and an hourly billing rate.
Re: [sqlite] Compress function
Do you know for how much money? On 7/19/06, Jay Sprenkle <[EMAIL PROTECTED]> wrote: The author of Sqlite also sells a version that compresses and encrypts the database. On 7/19/06, Cesar David Rodas Maldonado <[EMAIL PROTECTED]> wrote: > Thanks Hugh, i think it will be useful for me... > > On Wed, 19 Jul 2006 16:07 +0100 (BST), Hugh Gibson <[EMAIL PROTECTED]> > wrote: > > > > You could try http://web.utk.edu/~jplyon/sqlite/code/sqaux-userfns.cbut > > it's a little old now.
Re: [sqlite] Compress function
The author of Sqlite also sells a version that compresses and encrypts the database. On 7/19/06, Cesar David Rodas Maldonado <[EMAIL PROTECTED]> wrote: Thanks Hugh, i think it will be useful for me... On Wed, 19 Jul 2006 16:07 +0100 (BST), Hugh Gibson <[EMAIL PROTECTED]> wrote: > > You could try http://web.utk.edu/~jplyon/sqlite/code/sqaux-userfns.c but > it's a little old now.
Re: [sqlite] Compress function
Thanks Hugh, i think it will be useful for me... On Wed, 19 Jul 2006 16:07 +0100 (BST), Hugh Gibson <[EMAIL PROTECTED]> wrote: You could try http://web.utk.edu/~jplyon/sqlite/code/sqaux-userfns.c but it's a little old now. Hugh
Re: [sqlite] Compress function
You could try http://web.utk.edu/~jplyon/sqlite/code/sqaux-userfns.c but it's a little old now. Hugh