System.Data.SQLite
Check-in [a31cac5d59]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the SQLiteDataReader.StepCount property to return the number of rows seen so far.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a31cac5d59235501c23f1193e927e841ff626e9f
User & Date: mistachkin 2014-03-12 22:56:22
Context
2014-03-18
23:12
Add StickyHasRows connection flag to cause the SQLiteDataReader.HasRows property to return non-zero if there were ever any rows in the associated result sets. check-in: baf17cba3c user: mistachkin tags: trunk
2014-03-14
20:20
Add StickyHasRows connection flag to cause the SQLiteDataReader.HasRows property to return non-zero if there were ever any rows in the associated result sets. Closed-Leaf check-in: 59bbbbfcdb user: mistachkin tags: stickyHasRows
2014-03-12
22:56
Add the SQLiteDataReader.StepCount property to return the number of rows seen so far. check-in: a31cac5d59 user: mistachkin tags: trunk
20:50
Add a test for the SQLiteDataReader.HasRows property. check-in: 7fb5c1cd3e user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Doc/Extra/Provider/version.html.

44
45
46
47
48
49
50

51
52
53
54
55
56
57
    <div id="mainBody">
    <h1 class="heading">Version History</h1>
    <p><b>1.0.92.0 - March XX, 2014 <font color="red">(release scheduled)</font></b></p>
    <ul>
      <li>Updated to <a href="http://www.sqlite.org/releaselog/3_8_4_1.html">SQLite 3.8.4.1</a>.</li>
      <li>Update the list of keywords returned by SQLiteConnection.GetSchema(&quot;ReservedWords&quot;).&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Raise the static SQLiteConnection.Changed event when any SQLiteCommand or SQLiteDataReader object is closed or disposed.</li>

      <li>When the TraceWarning connection flag is set, issue warnings about possibly malformed UNC paths. Pursuant to <a href="http://system.data.sqlite.org/index.html/info/283344397b">[283344397b]</a>.</li>
      <li>Convert the primary NuGet package, &quot;System.Data.SQLite&quot;, into a meta-package.</li>
      <li>Enhancements to the NuGet packages, including the new &quot;modular&quot; packages.</li>
    </ul>
    <p><b>1.0.91.0 - February 12, 2014</b></p>
    <ul>
      <li>Updated to <a href="http://www.sqlite.org/releaselog/3_8_3_1.html">SQLite 3.8.3.1</a>.</li>







>







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
    <div id="mainBody">
    <h1 class="heading">Version History</h1>
    <p><b>1.0.92.0 - March XX, 2014 <font color="red">(release scheduled)</font></b></p>
    <ul>
      <li>Updated to <a href="http://www.sqlite.org/releaselog/3_8_4_1.html">SQLite 3.8.4.1</a>.</li>
      <li>Update the list of keywords returned by SQLiteConnection.GetSchema(&quot;ReservedWords&quot;).&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Raise the static SQLiteConnection.Changed event when any SQLiteCommand or SQLiteDataReader object is closed or disposed.</li>
      <li>Add the SQLiteDataReader.StepCount property to return the number of rows seen so far.</li>
      <li>When the TraceWarning connection flag is set, issue warnings about possibly malformed UNC paths. Pursuant to <a href="http://system.data.sqlite.org/index.html/info/283344397b">[283344397b]</a>.</li>
      <li>Convert the primary NuGet package, &quot;System.Data.SQLite&quot;, into a meta-package.</li>
      <li>Enhancements to the NuGet packages, including the new &quot;modular&quot; packages.</li>
    </ul>
    <p><b>1.0.91.0 - February 12, 2014</b></p>
    <ul>
      <li>Updated to <a href="http://www.sqlite.org/releaselog/3_8_3_1.html">SQLite 3.8.3.1</a>.</li>

Changes to System.Data.SQLite/SQLiteDataReader.cs.

43
44
45
46
47
48
49





50
51
52
53
54
55
56
...
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
...
306
307
308
309
310
311
312














313
314
315
316
317
318
319
....
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
....
1270
1271
1272
1273
1274
1275
1276

1277
1278
1279
1280
1281
1282
1283
....
1423
1424
1425
1426
1427
1428
1429


1430
1431
1432
1433
1434
1435
1436
    /// Number of records affected by the insert/update statements executed on the command
    /// </summary>
    private int _rowsAffected;
    /// <summary>
    /// Count of fields (columns) in the row-returning statement currently being processed
    /// </summary>
    private int _fieldCount;





    /// <summary>
    /// Maps the field (column) names to their corresponding indexes within the results.
    /// </summary>
    private Dictionary<string, int> _fieldIndexes;
    /// <summary>
    /// Datatypes of active fields (columns) in the current statement, used for type-restricting data
    /// </summary>
................................................................................
    /// </summary>
    /// <param name="disposing"></param>
    protected override void Dispose(bool disposing)
    {
        SQLiteConnection.OnChanged(GetConnection(this),
            new ConnectionEventArgs(SQLiteConnectionEventType.DisposingDataReader,
            null, null, _command, this, null, null, new object[] { disposing,
            disposed, _commandBehavior, _readingState, _rowsAffected, _fieldCount,
            _disposeCommand, _throwOnDisposed }));

        try
        {
            if (!disposed)
            {
                //if (disposing)
                //{
................................................................................
    public override void Close()
    {
      CheckDisposed();

      SQLiteConnection.OnChanged(GetConnection(this),
          new ConnectionEventArgs(SQLiteConnectionEventType.ClosingDataReader,
          null, null, _command, this, null, null, new object[] { _commandBehavior,
          _readingState, _rowsAffected, _fieldCount, _disposeCommand,
          _throwOnDisposed }));

      try
      {
        if (_command != null)
        {
          try
................................................................................

        if (_keyInfo == null)
          return _fieldCount;

        return _fieldCount + _keyInfo.Count;
      }
    }















    /// <summary>
    /// Returns the number of visible fields in the current resultset
    /// </summary>
    public override int VisibleFieldCount
    {
      get
................................................................................
          {
            for (; ; )
            {
              stmt = _command.GetStatement(_activeStatementIndex + 1);
              if (stmt == null) break;
              _activeStatementIndex++;

              if (!schemaOnly) stmt._sql.Step(stmt);
              if (stmt._sql.ColumnCount(stmt) == 0)
              {
                if (_rowsAffected == -1) _rowsAffected = 0;
                int changes = 0;
                if (stmt.TryGetChanges(ref changes))
                    _rowsAffected += changes;
                else
................................................................................
        fieldCount = stmt._sql.ColumnCount(stmt);

        // If the statement is not a select statement or we're not retrieving schema only, then perform the initial step
        if (!schemaOnly || (fieldCount == 0))
        {
          if (!schemaOnly && stmt._sql.Step(stmt))
          {

            _readingState = -1;
          }
          else if (fieldCount == 0) // No rows returned, if fieldCount is zero, skip to the next statement
          {
            if (_rowsAffected == -1) _rowsAffected = 0;
            int changes = 0;
            if (stmt.TryGetChanges(ref changes))
................................................................................
      else if (_readingState == 0) // Actively reading rows
      {
        // Don't read a new row if the command behavior dictates SingleRow.  We've already read the first row.
        if ((_commandBehavior & CommandBehavior.SingleRow) == 0)
        {
          if (_activeStatement._sql.Step(_activeStatement) == true)
          {


            if (_keyInfo != null)
              _keyInfo.Reset();

            return true;
          }
        }








>
>
>
>
>







 







|
|







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>







 







>
>







43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
...
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
...
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
....
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
....
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
....
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
    /// Number of records affected by the insert/update statements executed on the command
    /// </summary>
    private int _rowsAffected;
    /// <summary>
    /// Count of fields (columns) in the row-returning statement currently being processed
    /// </summary>
    private int _fieldCount;
    /// <summary>
    /// The number of calls to Step() that have returned true (i.e. the number of rows that
    /// have been read in the current result set).
    /// </summary>
    private int _stepCount;
    /// <summary>
    /// Maps the field (column) names to their corresponding indexes within the results.
    /// </summary>
    private Dictionary<string, int> _fieldIndexes;
    /// <summary>
    /// Datatypes of active fields (columns) in the current statement, used for type-restricting data
    /// </summary>
................................................................................
    /// </summary>
    /// <param name="disposing"></param>
    protected override void Dispose(bool disposing)
    {
        SQLiteConnection.OnChanged(GetConnection(this),
            new ConnectionEventArgs(SQLiteConnectionEventType.DisposingDataReader,
            null, null, _command, this, null, null, new object[] { disposing,
            disposed, _commandBehavior, _readingState, _rowsAffected, _stepCount,
            _fieldCount, _disposeCommand, _throwOnDisposed }));

        try
        {
            if (!disposed)
            {
                //if (disposing)
                //{
................................................................................
    public override void Close()
    {
      CheckDisposed();

      SQLiteConnection.OnChanged(GetConnection(this),
          new ConnectionEventArgs(SQLiteConnectionEventType.ClosingDataReader,
          null, null, _command, this, null, null, new object[] { _commandBehavior,
          _readingState, _rowsAffected, _stepCount, _fieldCount, _disposeCommand,
          _throwOnDisposed }));

      try
      {
        if (_command != null)
        {
          try
................................................................................

        if (_keyInfo == null)
          return _fieldCount;

        return _fieldCount + _keyInfo.Count;
      }
    }

    /// <summary>
    /// Returns the number of rows seen so far in the current result set.
    /// </summary>
    public int StepCount
    {
        get
        {
            CheckDisposed();
            CheckClosed();

            return _stepCount;
        }
    }

    /// <summary>
    /// Returns the number of visible fields in the current resultset
    /// </summary>
    public override int VisibleFieldCount
    {
      get
................................................................................
          {
            for (; ; )
            {
              stmt = _command.GetStatement(_activeStatementIndex + 1);
              if (stmt == null) break;
              _activeStatementIndex++;

              if (!schemaOnly && stmt._sql.Step(stmt)) _stepCount++;
              if (stmt._sql.ColumnCount(stmt) == 0)
              {
                if (_rowsAffected == -1) _rowsAffected = 0;
                int changes = 0;
                if (stmt.TryGetChanges(ref changes))
                    _rowsAffected += changes;
                else
................................................................................
        fieldCount = stmt._sql.ColumnCount(stmt);

        // If the statement is not a select statement or we're not retrieving schema only, then perform the initial step
        if (!schemaOnly || (fieldCount == 0))
        {
          if (!schemaOnly && stmt._sql.Step(stmt))
          {
            _stepCount++;
            _readingState = -1;
          }
          else if (fieldCount == 0) // No rows returned, if fieldCount is zero, skip to the next statement
          {
            if (_rowsAffected == -1) _rowsAffected = 0;
            int changes = 0;
            if (stmt.TryGetChanges(ref changes))
................................................................................
      else if (_readingState == 0) // Actively reading rows
      {
        // Don't read a new row if the command behavior dictates SingleRow.  We've already read the first row.
        if ((_commandBehavior & CommandBehavior.SingleRow) == 0)
        {
          if (_activeStatement._sql.Step(_activeStatement) == true)
          {
            _stepCount++;

            if (_keyInfo != null)
              _keyInfo.Reset();

            return true;
          }
        }

Changes to Tests/basic.eagle.

3006
3007
3008
3009
3010
3011
3012






















































3013
3014
3015
3016
3017
3018
3019

  unset -nocomplain error noRow db fileName
} -constraints \
{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
{False True True False True True False True True 1 True 0 False 0 False False\
True True False False True False False True 1 True 1 True 0 False False False\
True False False False False False False 1 True 1 True 1 True}}























































###############################################################################

reportSQLiteResources $test_channel

###############################################################################








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073

  unset -nocomplain error noRow db fileName
} -constraints \
{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
{False True True False True True False True True 1 True 0 False 0 False False\
True True False False True False False True 1 True 1 True 0 False False False\
True False False False False False False 1 True 1 True 1 True}}

###############################################################################

runTest {test data-1.64 {SQLiteDataReader StepCount property} -setup {
  setupDb [set fileName data-1.64.db]
} -body {
  sql execute $db {
    CREATE TABLE t1(x);
    CREATE TABLE t2(x);
    INSERT INTO t2 (x) VALUES(1);
    CREATE TABLE t3(x);
    INSERT INTO t3 (x) VALUES(1);
    INSERT INTO t3 (x) VALUES(2);
  }

  set reader(1) [sql execute -execute reader -format datareader -alias \
      $db "SELECT * FROM t1;"]

  set reader(2) [sql execute -execute reader -format datareader -alias \
      $db "SELECT * FROM t2;"]

  set reader(3) [sql execute -execute reader -format datareader -alias \
      $db "SELECT * FROM t3;"]

  set noRow "*: No current row*"

  list [$reader(1) StepCount] [$reader(2) StepCount] [$reader(3) StepCount] \
      [$reader(1) Read] [$reader(2) Read] [$reader(3) Read] \
      [$reader(1) StepCount] [$reader(2) StepCount] [$reader(3) StepCount] \
      [catch {$reader(1) Item x} error] [string match $noRow $error] \
      [catch {$reader(2) Item x} error] [string match $noRow $error] \
      [catch {$reader(3) Item x} error] [string match $noRow $error] \
      [$reader(1) StepCount] [$reader(2) StepCount] [$reader(3) StepCount] \
      [$reader(1) Read] [$reader(2) Read] [$reader(3) Read] \
      [$reader(1) StepCount] [$reader(2) StepCount] [$reader(3) StepCount] \
      [catch {$reader(1) Item x} error] [string match $noRow $error] \
      [catch {$reader(2) Item x} error] [string match $noRow $error] \
      [catch {$reader(3) Item x} error] [string match $noRow $error] \
      [$reader(1) StepCount] [$reader(2) StepCount] [$reader(3) StepCount] \
      [$reader(1) Read] [$reader(2) Read] [$reader(3) Read] \
      [$reader(1) StepCount] [$reader(2) StepCount] [$reader(3) StepCount] \
      [catch {$reader(1) Item x} error] [string match $noRow $error] \
      [catch {$reader(2) Item x} error] [string match $noRow $error] \
      [catch {$reader(3) Item x} error] [string match $noRow $error]
} -cleanup {
  unset -nocomplain reader

  cleanupDb $fileName

  unset -nocomplain error noRow db fileName
} -constraints \
{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
{0 1 1 False True True 0 1 1 1 True 0 False 0 False 0 1 1 False False True 0 1\
2 1 True 1 True 0 False 0 1 2 False False False 0 1 2 1 True 1 True 1 True}}

###############################################################################

reportSQLiteResources $test_channel

###############################################################################

Changes to readme.htm.

211
212
213
214
215
216
217

218
219
220
221
222
223
224
<p>
    <b>1.0.92.0 - March XX, 2014 <font color="red">(release scheduled)</font></b>
</p>
<ul>
    <li>Updated to <a href="http://www.sqlite.org/releaselog/3_8_4_1.html">SQLite 3.8.4.1</a>.</li>
    <li>Update the list of keywords returned by SQLiteConnection.GetSchema(&quot;ReservedWords&quot;).&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Raise the static SQLiteConnection.Changed event when any SQLiteCommand or SQLiteDataReader object is closed or disposed.</li>

    <li>When the TraceWarning connection flag is set, issue warnings about possibly malformed UNC paths. Pursuant to [283344397b].</li>
    <li>Convert the primary NuGet package, &quot;System.Data.SQLite&quot;, into a meta-package.</li>
    <li>Enhancements to the NuGet packages, including the new &quot;modular&quot; packages.</li>
</ul>
<p>
    <b>1.0.91.0 - February 12, 2014</b>
</p>







>







211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<p>
    <b>1.0.92.0 - March XX, 2014 <font color="red">(release scheduled)</font></b>
</p>
<ul>
    <li>Updated to <a href="http://www.sqlite.org/releaselog/3_8_4_1.html">SQLite 3.8.4.1</a>.</li>
    <li>Update the list of keywords returned by SQLiteConnection.GetSchema(&quot;ReservedWords&quot;).&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Raise the static SQLiteConnection.Changed event when any SQLiteCommand or SQLiteDataReader object is closed or disposed.</li>
    <li>Add the SQLiteDataReader.StepCount property to return the number of rows seen so far.</li>
    <li>When the TraceWarning connection flag is set, issue warnings about possibly malformed UNC paths. Pursuant to [283344397b].</li>
    <li>Convert the primary NuGet package, &quot;System.Data.SQLite&quot;, into a meta-package.</li>
    <li>Enhancements to the NuGet packages, including the new &quot;modular&quot; packages.</li>
</ul>
<p>
    <b>1.0.91.0 - February 12, 2014</b>
</p>

Changes to www/news.wiki.

5
6
7
8
9
10
11

12
13
14
15
16
17
18
<p>
    <b>1.0.92.0 - March XX, 2014 <font color="red">(release scheduled)</font></b>
</p>
<ul>
    <li>Updated to <a href="http://www.sqlite.org/releaselog/3_8_4_1.html">SQLite 3.8.4.1</a>.</li>
    <li>Update the list of keywords returned by SQLiteConnection.GetSchema(&quot;ReservedWords&quot;).&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Raise the static SQLiteConnection.Changed event when any SQLiteCommand or SQLiteDataReader object is closed or disposed.</li>

    <li>When the TraceWarning connection flag is set, issue warnings about possibly malformed UNC paths. Pursuant to [283344397b].</li>
    <li>Convert the primary NuGet package, &quot;System.Data.SQLite&quot;, into a meta-package.</li>
    <li>Enhancements to the NuGet packages, including the new &quot;modular&quot; packages.</li>
</ul>
<p>
    <b>1.0.91.0 - February 12, 2014</b>
</p>







>







5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<p>
    <b>1.0.92.0 - March XX, 2014 <font color="red">(release scheduled)</font></b>
</p>
<ul>
    <li>Updated to <a href="http://www.sqlite.org/releaselog/3_8_4_1.html">SQLite 3.8.4.1</a>.</li>
    <li>Update the list of keywords returned by SQLiteConnection.GetSchema(&quot;ReservedWords&quot;).&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Raise the static SQLiteConnection.Changed event when any SQLiteCommand or SQLiteDataReader object is closed or disposed.</li>
    <li>Add the SQLiteDataReader.StepCount property to return the number of rows seen so far.</li>
    <li>When the TraceWarning connection flag is set, issue warnings about possibly malformed UNC paths. Pursuant to [283344397b].</li>
    <li>Convert the primary NuGet package, &quot;System.Data.SQLite&quot;, into a meta-package.</li>
    <li>Enhancements to the NuGet packages, including the new &quot;modular&quot; packages.</li>
</ul>
<p>
    <b>1.0.91.0 - February 12, 2014</b>
</p>