@@ -62,6 +62,7 @@ public IDatabase Create(
6262
6363 // Auto-detect storage mode by file extension
6464 var options = DetectStorageMode ( dbPath , config ) ;
65+ options . IsReadOnly = isReadOnly ;
6566
6667 return CreateWithOptions ( dbPath , masterPassword , options ) ;
6768 }
@@ -104,7 +105,7 @@ private IDatabase CreateDirectoryDatabase(string dbPath, string masterPassword,
104105 {
105106 // For now, use existing Database class (will be refactored to use DirectoryStorageProvider)
106107 var config = options . DatabaseConfig ?? DatabaseConfig . Default ;
107- return new Database ( services , dbPath , masterPassword , false , config ) ;
108+ return new Database ( services , dbPath , masterPassword , options . IsReadOnly , config ) ;
108109 }
109110
110111 /// <summary>
@@ -224,13 +225,9 @@ public List<Dictionary<string, object>> ExecuteQuery(string sql, Dictionary<stri
224225 // Handle basic queries
225226 var upperSql = sql . Trim ( ) . ToUpperInvariant ( ) ;
226227
227- if ( upperSql . Contains ( "SELECT" ) )
228- {
229- // Use SingleFileSqlParser for queries
230- var sqlParser = new SingleFileSqlParser ( this , _tableDirectoryManager ) ;
231- return sqlParser . ExecuteQuery ( sql , parameters ?? new Dictionary < string , object ? > ( ) ) ;
232- }
233- else if ( upperSql . Contains ( "STORAGE" ) )
228+ // ✅ FIX: Check for special STORAGE table query FIRST (before general SELECT routing)
229+ // This handles: SELECT * FROM STORAGE, SELECT COUNT(*) FROM STORAGE, etc.
230+ if ( upperSql . Contains ( "FROM STORAGE" ) || upperSql . Contains ( "FROM[STORAGE]" ) )
234231 {
235232 // Return storage statistics
236233 var stats = GetStorageStatistics ( ) ;
@@ -246,6 +243,12 @@ public List<Dictionary<string, object>> ExecuteQuery(string sql, Dictionary<stri
246243 }
247244 ] ;
248245 }
246+ else if ( upperSql . Contains ( "SELECT" ) )
247+ {
248+ // Use SingleFileSqlParser for queries
249+ var sqlParser = new SingleFileSqlParser ( this , _tableDirectoryManager ) ;
250+ return sqlParser . ExecuteQuery ( sql , parameters ?? new Dictionary < string , object ? > ( ) ) ;
251+ }
249252
250253 throw new NotSupportedException ( $ "Query not supported in single-file mode: { sql } ") ;
251254 }
@@ -561,6 +564,24 @@ public void Insert(Dictionary<string, object> row)
561564 _storageProvider . WriteBlockAsync ( _dataBlockName , data ) . GetAwaiter ( ) . GetResult ( ) ;
562565 }
563566
567+ public long [ ] InsertBatch ( List < Dictionary < string , object > > rows )
568+ {
569+ // Not implemented for single-file storage - fall back to individual inserts
570+ var positions = new long [ rows . Count ] ;
571+ for ( int i = 0 ; i < rows . Count ; i ++ )
572+ {
573+ Insert ( rows [ i ] ) ;
574+ positions [ i ] = i ;
575+ }
576+ return positions ;
577+ }
578+
579+ public long [ ] InsertBatchFromBuffer ( ReadOnlySpan < byte > encodedData , int rowCount )
580+ {
581+ // Not implemented for single-file storage
582+ throw new NotImplementedException ( "InsertBatchFromBuffer is not supported for single-file storage" ) ;
583+ }
584+
564585 public void Update ( Dictionary < string , object > row )
565586 {
566587 // For simplicity, just append - real implementation would need indexing
@@ -636,25 +657,61 @@ public List<Dictionary<string, object>> Select()
636657 public List < Dictionary < string , object > > Select ( string ? whereClause , string ? orderBy , bool distinct = false , bool noEncrypt = false ) => Select ( ) ;
637658 public void Update ( string ? whereClause , Dictionary < string , object > updates ) => throw new NotImplementedException ( ) ;
638659 public void Delete ( string ? whereClause ) => throw new NotImplementedException ( ) ;
639- public void CreateHashIndex ( string columnName ) => throw new NotImplementedException ( ) ;
640- public void CreateHashIndex ( string indexName , string columnName ) => throw new NotImplementedException ( ) ;
660+ public void CreateHashIndex ( string columnName ) => throw new NotImplementedException ( "Hash indexes are not supported for single-file storage" ) ;
661+
662+ public void CreateHashIndex ( string indexName , string columnName , bool isUnique = false ) => throw new NotImplementedException ( "Named hash indexes are not supported for single-file storage" ) ;
663+
641664 public bool HasHashIndex ( string columnName ) => false ;
642- public ( int UniqueKeys , int TotalRows , double AvgRowsPerKey ) ? GetHashIndexStatistics ( string columnName ) => ( 0 , 0 , 0.0 ) ;
643- public void IncrementColumnUsage ( string columnName ) { }
665+
666+ public ( int UniqueKeys , int TotalRows , double AvgRowsPerKey ) ? GetHashIndexStatistics ( string columnName ) => null ;
667+
668+ public void IncrementColumnUsage ( string columnName )
669+ {
670+ // Not implemented for single-file storage
671+ }
672+
644673 public IReadOnlyDictionary < string , long > GetColumnUsage ( ) => new Dictionary < string , long > ( ) ;
645- public void TrackAllColumnsUsage ( ) { }
646- public void TrackColumnUsage ( string columnName ) { }
674+
675+ public void TrackAllColumnsUsage ( )
676+ {
677+ // Not implemented for single-file storage
678+ }
679+
680+ public void TrackColumnUsage ( string columnName )
681+ {
682+ // Not implemented for single-file storage
683+ }
684+
647685 public bool RemoveHashIndex ( string columnName ) => false ;
648- public void ClearAllIndexes ( ) => throw new NotImplementedException ( ) ;
649- public long GetCachedRowCount ( ) => _primaryKeyIndex . Count ;
650- public void RefreshRowCount ( ) { }
651- public void CreateBTreeIndex ( string columnName ) => throw new NotImplementedException ( ) ;
652- public void CreateBTreeIndex ( string indexName , string columnName ) => throw new NotImplementedException ( ) ;
686+
687+ public void ClearAllIndexes ( )
688+ {
689+ // Not implemented for single-file storage
690+ }
691+
692+ public long GetCachedRowCount ( ) => - 1 ;
693+
694+ public void RefreshRowCount ( )
695+ {
696+ // Not implemented for single-file storage
697+ }
698+
699+ public void CreateBTreeIndex ( string columnName ) => throw new NotImplementedException ( "B-tree indexes are not supported for single-file storage" ) ;
700+
701+ public void CreateBTreeIndex ( string indexName , string columnName , bool isUnique = false ) => throw new NotImplementedException ( "Named B-tree indexes are not supported for single-file storage" ) ;
702+
653703 public bool HasBTreeIndex ( string columnName ) => false ;
654- public long [ ] InsertBatch ( List < Dictionary < string , object > > rows ) => throw new NotImplementedException ( ) ;
655- public long [ ] InsertBatchFromBuffer ( ReadOnlySpan < byte > encodedData , int rowCount ) => throw new NotImplementedException ( ) ;
656- public void Flush ( ) { }
657- public void AddColumn ( ColumnDefinition columnDef ) => throw new NotImplementedException ( ) ;
704+
705+ public void Flush ( )
706+ {
707+ // Single-file storage handles flushing automatically
708+ }
709+
710+ public void AddColumn ( ColumnDefinition columnDef )
711+ {
712+ // Not implemented for single-file storage
713+ throw new NotImplementedException ( "Adding columns is not supported for single-file storage" ) ;
714+ }
658715
659716 /// <summary>
660717 /// Fallback deletion method for tables without a primary key.
0 commit comments