Hello!
Ok, I did realize this. Is my variant the best solution or I can enhance it?
static void distinctonFunc(
sqlite3_context *pCtx, /* Function context */
int nArg, /* Number of function arguments */
sqlite3_value **argv /* Values for all function arguments */
){
int i;
unsigned int *pHash;
unsigned int hash;
struct MurmurHash2A ctx;
MurmurHash2A_Begin(&ctx);
for(i=0; i < nArg; i++){
const char *zData = (char*)sqlite3_value_blob(argv[i]);
if( zData ){
MurmurHash2A_Add(&ctx,(unsigned char*)zData,
sqlite3_value_bytes(argv[i]));
}
}
hash = MurmurHash2A_End(&ctx);
pHash = (unsigned int*)sqlite3_get_auxdata(pCtx, 0);
if( pHash==0 ){
pHash = sqlite3_malloc( sizeof(*pHash) );
if( pHash==0 ){
sqlite3_result_error_nomem(pCtx);
return;
}
*pHash = hash;
sqlite3_set_auxdata(pCtx, 0, pHash, sqlite3_free);
sqlite3_result_int(pCtx, 1);
}else{
sqlite3_result_int(pCtx, *pHash==hash?0:1);
*pHash = hash;
}
}
create table t(id int, value int);
insert into t values(1,1);
insert into t values(2, 1);
insert into t values(3, 2);
insert into t values(4, 3);
insert into t values(5, 3);
insert into t values(6, 3);
insert into t values(7, 4);
insert into t values(8, 4);
insert into t values(9, 1);
insert into t values(10, 5);
insert into t values(11, 5);
insert into t values(12, 2);
insert into t values(13, 2);
select value from t where distincton(0,value)=1;
1
2
3
4
1
5
2
Best regards, Alexey Pechnikov.
http://pechnikov.tel/
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users