![]() ![]() Afterwards, they are invoked by SQLite as callbacks if they are present in SQL statements. The function sqlite3_create_function() allows to register a new user-defined function, which must comply with a standard profile. SQLite makes it possible to extend the set of functions that can be called in SQL statements. UPDATE test_with_blob set my_blob = readfile('/home/dmadmin/dmgawk/gawk-4.2.1/extension/sqlite_gawk.c') where n1 = 1000 SELECT n1, writefile('yy' || rowid, my_blob) FROM test_with_blob ![]() INSERT INTO test_with_blob(n1, my_blob) VALUES(1, readfile("gawk-4.2.1.tar.gz") These functions can then be used seamlessly as follows: It provides the SQL extension functions readfile() (read file into a blob) and writefile() (dumps a blob into file) for working with blobs from SQL statements. Lines 77 to 315: this code has been lifted from sqlite3.c, the SQLite shell, and only slightly edited. Line 56: Some initialization is performed, mostly of the array of database handles. When a database is closed, the free slot is of course recycled for the next database to open. The array has a fixed size of 100 for up to 100 concurrently opened database, which should be largely enough (if not, just increase MAX_DB on line 46 and recompile, or implement a dynamically resizable array instead). Obviously, gawk does not know pointers therefore what gets returned to gawk after a database has been opened is an integer which is an index into a static array of (sqlite3 *). Line 48: All the operations on a database requires a handle that is initialized once the database is successfully opened. This part is best read while having Part II opened in another browser window. In this final part, I’ll explain succinctly the code that was listed in part II. Welcome to part III of a three-part article on extending gawk with a SQLite binding. ![]()
0 Comments
Leave a Reply. |