Skip to content

Commit

Permalink
keep the default ordering if the user does not specify an ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
tantaman committed Jun 29, 2023
1 parent 8432f50 commit c9f8c85
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
10 changes: 5 additions & 5 deletions core/src/changes-vtab-read.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ static void testChangesUnionQuery() {
assert(rc == SQLITE_OK);

char *query = crsql_changesUnionQuery(tblInfos, 2, "");
printf("Query: X%sX", query);
assert(
strcmp(
query,
Expand All @@ -76,10 +75,12 @@ static void testChangesUnionQuery() {
"__crsql_col_version as col_vrsn, __crsql_db_version as "
"db_vrsn, __crsql_site_id as site_id, _rowid_, "
"__crsql_seq as seq FROM "
"\"bar__crsql_clock\") ORDER BY db_vrsn, seq ASC") == 0);
"\"bar__crsql_clock\") ") == 0);
sqlite3_free(query);

query = crsql_changesUnionQuery(tblInfos, 2, "site_id IS ? AND db_vrsn > ?");
query = crsql_changesUnionQuery(tblInfos, 2,
"WHERE site_id IS ? AND db_vrsn > ?");
printf("Query: X%sX", query);
assert(
strcmp(
query,
Expand All @@ -94,8 +95,7 @@ static void testChangesUnionQuery() {
"__crsql_col_version as col_vrsn, __crsql_db_version as "
"db_vrsn, __crsql_site_id as site_id, _rowid_, "
"__crsql_seq as seq FROM "
"\"bar__crsql_clock\") WHERE site_id IS ? AND db_vrsn > ? ORDER "
"BY db_vrsn, seq ASC") == 0);
"\"bar__crsql_clock\") WHERE site_id IS ? AND db_vrsn > ?") == 0);
sqlite3_free(query);

printf("\t\e[0;32mSuccess\e[0m\n");
Expand Down
4 changes: 4 additions & 0 deletions core/src/changes-vtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ static int changesBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo) {
int desc = 0;
if (pIdxInfo->nOrderBy > 0) {
sqlite3_str_appendall(pStr, " ORDER BY ");
} else {
// The user didn't provide an ordering? Tack on a default one that will
// retrieve changes in-order
sqlite3_str_appendall(pStr, " ORDER BY db_vrsn, seq ASC");
}
firstConstraint = 1;
for (int i = 0; i < pIdxInfo->nOrderBy; i++) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/rows-impacted.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ void rowsImpactedTestSuite() {
testManyTxns();
testUpdateThatDoesNotChangeAnything();
testDeleteThatDoesNotChangeAnything();
testCreateThatDoesNotChangeAnything();
testValueWin();
testClockWin();
testDelete();
}
2 changes: 1 addition & 1 deletion py/correctness/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

source env/bin/activate
python -m pytest tests -s -k test_crsql_changes_filters
python -m pytest tests -s

# -k test_sync_prop.py
4 changes: 2 additions & 2 deletions py/correctness/tests/test_sync_prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ def sync_from_random_peers(num_peers_to_sync, db, dbs, since_is_rowid):
def sync_left_to_right(l, r, since, since_is_rowid):
if since_is_rowid:
changes = l.execute(
"SELECT *, rowid FROM crsql_changes WHERE rowid > ?", (since,))
"SELECT *, rowid FROM crsql_changes WHERE rowid > ? ORDER BY db_version, seq ASC", (since,))
else:
changes = l.execute(
"SELECT * FROM crsql_changes WHERE db_version > ?", (since,))
"SELECT * FROM crsql_changes WHERE db_version > ? ORDER BY db_version, seq ASC", (since,))

ret = 0
for change in changes:
Expand Down

0 comments on commit c9f8c85

Please sign in to comment.