@@ -970,11 +970,27 @@ public T ExecuteScalar<T> (string query, params object[] args)
970970 var cmd = CreateCommand ( query , args ) ;
971971 return cmd . ExecuteQuery < T > ( ) ;
972972 }
973- public List < T > SingleQuery < T > ( string query , params object [ ] args )
973+
974+ /// <summary>
975+ /// Creates a SQLiteCommand given the command text (SQL) with arguments. Place a '?'
976+ /// in the command text for each of the arguments and then executes that command.
977+ /// It returns the first column of each row of the result.
978+ /// </summary>
979+ /// <param name="query">
980+ /// The fully escaped SQL.
981+ /// </param>
982+ /// <param name="args">
983+ /// Arguments to substitute for the occurences of '?' in the query.
984+ /// </param>
985+ /// <returns>
986+ /// An enumerable with one result for the first column of each row returned by the query.
987+ /// </returns>
988+ public List < T > QueryScalars < T > ( string query , params object [ ] args )
974989 {
975990 var cmd = CreateCommand ( query , args ) ;
976- return cmd . ExcuteSingleQuery < T > ( ) . ToList ( ) ;
991+ return cmd . ExecuteQueryScalars < T > ( ) . ToList ( ) ;
977992 }
993+
978994 /// <summary>
979995 /// Creates a SQLiteCommand given the command text (SQL) with arguments. Place a '?'
980996 /// in the command text for each of the arguments and then executes that command.
@@ -2849,31 +2865,6 @@ protected virtual void OnInstanceCreated (object obj)
28492865 {
28502866 // Can be overridden.
28512867 }
2852- public IEnumerable < T > ExcuteSingleQuery < T > ( )
2853- {
2854- if ( _conn . Trace ) {
2855- _conn . Tracer ? . Invoke ( "Executing Query: " + this ) ;
2856- }
2857- var stmt = Prepare ( ) ;
2858- try {
2859- if ( SQLite3 . ColumnCount ( stmt ) != 1 ) {
2860- throw new NotSupportedException ( "Column count error" ) ;
2861- }
2862- while ( SQLite3 . Step ( stmt ) == SQLite3 . Result . Row ) {
2863- var colType = SQLite3 . ColumnType ( stmt , 0 ) ;
2864- var val = ReadCol ( stmt , 0 , colType , typeof ( T ) ) ;
2865- if ( val == null ) {
2866- yield return default ( T ) ;
2867- }
2868- else {
2869- yield return ( T ) val ;
2870- }
2871- }
2872- }
2873- finally {
2874- Finalize ( stmt ) ;
2875- }
2876- }
28772868
28782869 public IEnumerable < T > ExecuteDeferredQuery < T > ( TableMapping map )
28792870 {
@@ -2940,6 +2931,32 @@ public T ExecuteScalar<T> ()
29402931 return val ;
29412932 }
29422933
2934+ public IEnumerable < T > ExecuteQueryScalars < T > ( )
2935+ {
2936+ if ( _conn . Trace ) {
2937+ _conn . Tracer ? . Invoke ( "Executing Query: " + this ) ;
2938+ }
2939+ var stmt = Prepare ( ) ;
2940+ try {
2941+ if ( SQLite3 . ColumnCount ( stmt ) < 1 ) {
2942+ throw new InvalidOperationException ( "QueryScalars should return at least one column" ) ;
2943+ }
2944+ while ( SQLite3 . Step ( stmt ) == SQLite3 . Result . Row ) {
2945+ var colType = SQLite3 . ColumnType ( stmt , 0 ) ;
2946+ var val = ReadCol ( stmt , 0 , colType , typeof ( T ) ) ;
2947+ if ( val == null ) {
2948+ yield return default ( T ) ;
2949+ }
2950+ else {
2951+ yield return ( T ) val ;
2952+ }
2953+ }
2954+ }
2955+ finally {
2956+ Finalize ( stmt ) ;
2957+ }
2958+ }
2959+
29432960 public void Bind ( string name , object val )
29442961 {
29452962 _bindings . Add ( new Binding {
0 commit comments