11 aug 2016, om 13:10, Anthony Lansbergen:

Hello,

I needed a way to make parameterized texts for logging in my current project. For this purpose I missed a function in sqlite: group_replace, so I made an extension. The function is just like group_concat, an aggregate function, but it replaces keys with values in a string instead of concattenating strings.

I put the code online, it's publicly available at:

https://github.com/adesys/sqlite3_group_replace_extension

It seems to work fine, but since this is my first extension, can someone please take a look at it and check if it is bug free :-)

thanks in advance,
Anthony Lansbergen

Hello, I am not very experienced. I do have an easy test to check memory leak. It runs on OS X. For group_replace i tested the script below and that shows increasing memory use. Two remarks/questions: 1. better use sqlite3_malloc and sqlite3_free instead of the C primitives. 2. is it imaginable to obtain the same functionality without a C extension, by using plain replace() inside a recursive CTE?
Thanks, E. Pasma

.load ./sqlite3_group_replace_extension
create table kv (k, v, reverse);
insert into kv values ('1', 'one',0),('2','two',0),('3','knock knock knock',0);
insert into kv select v,k,1 from kv;
create view v as
with r as  (
select 0 as i, '1 2 3 4 5 6 7 8 9' as s
union all
select i+1, (select group_replace (s, k, v) from kv where reverse=i%2)
from r where i<100000
)
select * from r where i>=100000-1
;
select * from v;
.system ps -o vsz -o command|grep sqlite3$
select * from v;
.system ps -o vsz -o command|grep sqlite3$
select * from v;
.system ps -o vsz -o command|grep sqlite3$

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to