Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Under the covers sqlite-net does some amazing things in an attempt to manage queries and connections for you. </p> <p>For example, the line </p> <pre><code>var data = db.Table&lt;tablename&gt;().Where(...) </code></pre> <p>Does not actually establish a connection or execute anything against the database. Instead, it creates an instance of a class called TableQuery which is enumerable.</p> <p>When you call </p> <pre><code>int iDataCount = data.Count(); </code></pre> <p>TableQuery actually executes</p> <pre><code>GenerateCommand("count(*)").ExecuteScalar&lt;int&gt;(); </code></pre> <p>When you call</p> <pre><code>Elements = data.ElementAt(i); </code></pre> <p>TableQuery actually calls </p> <pre><code>return Skip(index).Take(1).First(); </code></pre> <p><strong>Take(1).First()</strong> eventually calls <strong>GetEnumerator</strong>, which compiles a SQLite command, executes it with TOP 1, and serializes the result back into your data class.</p> <p>So, basically, every time you call <strong>data.ElementAt</strong> you are executing another query. This is different from standard .NET enumerations where you are just accessing an element in a collection or array.</p> <p>I believe this is the root of your problem. I would recommend that instead of getting the count and using a <strong>for(i, ...)</strong> loop, you simply do <strong>foreach (tablename tn in data)</strong>. This will cause all records to be fetched at once instead of record by record in the loop. That alone may be enough to close the query and allow you to delete the table during the loop. If not, I recommend you create a collection and add each SID to the collection during the loop. Then, after the loop go back and remove the sids in another pass. Worst case scenario, you could close the connection between loops.</p> <p>Hope that helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload