@@ -289,7 +289,7 @@ FROM ExecutionHistory eh
289289 createTablesCommand . ExecuteNonQuery ( ) ;
290290
291291 // Migrate existing text file history if it exists
292- // MigrateTextHistoryToSQLite(connection);
292+ MigrateTextHistoryToSQLite ( connection ) ;
293293 }
294294 }
295295 catch ( SqliteException ex )
@@ -304,16 +304,15 @@ FROM ExecutionHistory eh
304304
305305 private void MigrateTextHistoryToSQLite ( SqliteConnection connection )
306306 {
307- // Check if text history file exists
308- string textHistoryPath = _options . HistorySavePath . Replace ( ".sqlite" , ".txt" ) ;
307+ // Derive the text history path from the SQLite path.
308+ // Both files share the same directory and host prefix:
309+ // ConsoleHost_history.txt (text)
310+ // ConsoleHost_history.db (SQLite)
311+ // By the time this runs, HistorySavePath is already the .db path.
312+ string textHistoryPath = Path . ChangeExtension ( _options . HistorySavePath , ".txt" ) ;
309313 if ( ! File . Exists ( textHistoryPath ) )
310314 {
311- // Try default history path pattern
312- textHistoryPath = Path . ChangeExtension ( _options . HistorySavePath , ".txt" ) ;
313- if ( ! File . Exists ( textHistoryPath ) )
314- {
315- return ; // No text history to migrate
316- }
315+ return ; // No text history to migrate
317316 }
318317
319318 try
@@ -518,12 +517,15 @@ private long GetOrCreateCommandId(SqliteConnection connection, string commandLin
518517 using var insertCommand = connection . CreateCommand ( ) ;
519518 insertCommand . CommandText = @"
520519INSERT INTO Commands (CommandLine, CommandHash)
521- VALUES (@CommandLine, @CommandHash)
522- RETURNING Id" ;
520+ VALUES (@CommandLine, @CommandHash)" ;
523521 insertCommand . Parameters . AddWithValue ( "@CommandLine" , commandLine ) ;
524522 insertCommand . Parameters . AddWithValue ( "@CommandHash" , commandHash ) ;
523+ insertCommand . ExecuteNonQuery ( ) ;
525524
526- return Convert . ToInt64 ( insertCommand . ExecuteScalar ( ) ) ;
525+ // Get the inserted row ID
526+ using var lastIdCommand = connection . CreateCommand ( ) ;
527+ lastIdCommand . CommandText = "SELECT last_insert_rowid()" ;
528+ return Convert . ToInt64 ( lastIdCommand . ExecuteScalar ( ) ) ;
527529 }
528530
529531 // Helper method to get or create a location ID
@@ -544,11 +546,14 @@ private long GetOrCreateLocationId(SqliteConnection connection, string location)
544546 using var insertCommand = connection . CreateCommand ( ) ;
545547 insertCommand . CommandText = @"
546548INSERT INTO Locations (Path)
547- VALUES (@Path)
548- RETURNING Id" ;
549+ VALUES (@Path)" ;
549550 insertCommand . Parameters . AddWithValue ( "@Path" , location ) ;
551+ insertCommand . ExecuteNonQuery ( ) ;
550552
551- return Convert . ToInt64 ( insertCommand . ExecuteScalar ( ) ) ;
553+ // Get the inserted row ID
554+ using var lastIdCommand = connection . CreateCommand ( ) ;
555+ lastIdCommand . CommandText = "SELECT last_insert_rowid()" ;
556+ return Convert . ToInt64 ( lastIdCommand . ExecuteScalar ( ) ) ;
552557 }
553558
554559 private void WriteHistoryToSQLite ( int start , int end )
@@ -1442,17 +1447,7 @@ private void HistoryRecall(int direction)
14421447 }
14431448 _recallHistoryCommandCount += 1 ;
14441449
1445- // For SQLite/location-filtered history, allow returning to the current line
1446- if ( _options . HistoryType == HistoryType . SQLite &&
1447- ( newHistoryIndex < 0 || newHistoryIndex >= _history . Count ) )
1448- {
1449- _currentHistoryIndex = _history . Count ;
1450- var moveCursor = InViCommandMode ( ) && ! _options . HistorySearchCursorMovesToEnd
1451- ? HistoryMoveCursor . ToBeginning
1452- : HistoryMoveCursor . ToEnd ;
1453- UpdateFromHistory ( moveCursor ) ;
1454- }
1455- else if ( newHistoryIndex >= 0 && newHistoryIndex <= _history . Count )
1450+ if ( newHistoryIndex >= 0 && newHistoryIndex <= _history . Count )
14561451 {
14571452 _currentHistoryIndex = newHistoryIndex ;
14581453 var moveCursor = InViCommandMode ( ) && ! _options . HistorySearchCursorMovesToEnd
0 commit comments