Note that there are some explanatory texts on larger screens.

plurals
  1. POSystem.Data.SQLite equivalent for SqlDbType.Structured?
    primarykey
    data
    text
    <p>On the current project I'm working on, I often have a collection of up to a 1000 (<code>int</code> or <code>string</code>) values, I want to match in a select statement (using the IN operator). The project supports both SQL Server and SQLite.</p> <p>In SQL Server the solution is pretty easy. I created 2 new types:</p> <pre><code>CREATE TYPE IntegerList AS TABLE(IntValue INT NOT NULL); CREATE TYPE StringList AS TABLE(StrValue VARCHAR(32) NOT NULL); </code></pre> <p>In my C# code I do as follows:</p> <pre><code>using (IDbCommand command = connection.CreateCommand()) { command.CommandText = someComplexSelectStatment + " AND T.Value IN (SELECT StrValue FROM @Values)"; SqlParameter parameter = command.CreateParameter() as SqlParameter; parameter.ParameterName = "@Values"; parameter.Value = data; parameter.SqlDbType = SqlDbType.Structured; parameter.TypeName = "dbo.StringList"; command.Parameters.Add(parameter); // use an IDataReader to retrieve the results } </code></pre> <p>Where data is a <code>DataTable</code> of a <code>DbDataReader</code>. I've written my own generic <code>DbDataReader</code>, which is able to use an <code>IEnumerable&lt;T&gt;</code> as source.</p> <p>Is there any equivalent to do this in SQLite ? The only solution I see (apart from inserting the data into a temporary table), would be to create a huge string like: <code>... AND T.Value IN ('Value1','Value2','Value3',...)</code>. This does not seem a very performant solution to me.</p> <p>I can not perform the select statement without the IN operator (and filter the result on the collection) as the result would contain too many results (up to a million records).</p> <p>Marc</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. 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