Skip to content

Commit 9c6d4c0

Browse files
Change SessionFsSqliteResult.Rows to IList<object?[]> and LastInsertRowid to long?
Rows are now positional arrays aligned with the Columns list, avoiding redundant dictionary key construction. The bridge code converts to keyed dictionaries for the wire format. LastInsertRowid changed from double? to long? since SQLite row IDs are always integers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ee5d33a commit 9c6d4c0

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

dotnet/src/SessionFsProvider.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ public class SessionFsSqliteResult
1616
/// <summary>Column names from the result set.</summary>
1717
public IList<string> Columns { get; set; } = [];
1818

19-
/// <summary>For SELECT: array of row objects. For others: empty array.</summary>
20-
public IList<IDictionary<string, object>> Rows { get; set; } = [];
19+
/// <summary>For SELECT: rows as positional arrays aligned with <see cref="Columns"/>. For others: empty.</summary>
20+
public IList<object?[]> Rows { get; set; } = [];
2121

2222
/// <summary>Number of rows affected (for INSERT/UPDATE/DELETE).</summary>
2323
public long RowsAffected { get; set; }
2424

2525
/// <summary>Last inserted row ID (for INSERT).</summary>
26-
public double? LastInsertRowid { get; set; }
26+
public long? LastInsertRowid { get; set; }
2727
}
2828

2929
/// <summary>
@@ -288,10 +288,25 @@ async Task<SessionFsSqliteQueryResult> ISessionFsHandler.SqliteQueryAsync(Sessio
288288
try
289289
{
290290
var result = await sqliteProvider.QueryAsync(request.QueryType, request.Query, request.Params, cancellationToken).ConfigureAwait(false);
291+
var columns = result?.Columns ?? [];
292+
var rows = result?.Rows ?? [];
293+
294+
// Convert positional arrays to keyed dictionaries for the wire format.
295+
var keyedRows = new List<IDictionary<string, object>>(rows.Count);
296+
foreach (var row in rows)
297+
{
298+
var dict = new Dictionary<string, object>(columns.Count);
299+
for (var i = 0; i < columns.Count && i < row.Length; i++)
300+
{
301+
dict[columns[i]] = row[i]!;
302+
}
303+
keyedRows.Add(dict);
304+
}
305+
291306
return new SessionFsSqliteQueryResult
292307
{
293-
Rows = result?.Rows ?? [],
294-
Columns = result?.Columns ?? [],
308+
Rows = keyedRows,
309+
Columns = columns,
295310
RowsAffected = result?.RowsAffected ?? 0,
296311
LastInsertRowid = result?.LastInsertRowid,
297312
};

dotnet/test/E2E/InMemorySessionFsSqliteHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ private SqliteConnection GetOrCreateDb()
7777
columns.Add(reader.GetName(i));
7878
}
7979

80-
var rows = new List<IDictionary<string, object>>();
80+
var rows = new List<object?[]>();
8181
while (reader.Read())
8282
{
83-
var row = new Dictionary<string, object>();
83+
var row = new object?[reader.FieldCount];
8484
for (var i = 0; i < reader.FieldCount; i++)
8585
{
86-
row[reader.GetName(i)] = reader.IsDBNull(i) ? null! : reader.GetValue(i);
86+
row[i] = reader.IsDBNull(i) ? null : reader.GetValue(i);
8787
}
8888
rows.Add(row);
8989
}

0 commit comments

Comments
 (0)