Make sqlite query dynamic