Re: [sqlite] Semantics regarding command instances and queries in the C# client

2017-04-28 Thread Clemens Ladisch
Joseph L. Casale wrote:
> that practice looks a bit ugly.

Show some example.


Regards,
Clemens
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Semantics regarding command instances and queries in the C# client

2017-04-28 Thread Joseph L. Casale
From: sqlite-users  on behalf of 
Clemens Ladisch 
Sent: Friday, April 28, 2017 2:51 AM
To: sqlite-users@mailinglists.sqlite.org
Subject: Re: [sqlite] Semantics regarding command instances and queries in the 
C# client 
    
> Show some example.

Hey Clemens,
Check out this paste for a quick script quality console app I wrote to help a 
user consume
some data from a collection of csv files into an SQLite database.

https://paste.ofcode.org/bFQnrpeQdCkqUES7zfjuZe

Each row from the CSV required several tables with relationships to be 
populated. One could
certainly abstract this out into an api, but that can have impacts on 
performance for large
batch processing if you are creating parameters for every insert rather than 
reusing them.

In simple cases, the code is trivial but in this example, it looks terrible 
given the number of
Command instances...

Thanks for any opinions,
jlc
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Semantics regarding command instances and queries in the C# client

2017-04-28 Thread Clemens Ladisch
Joseph L. Casale wrote:
> Each row from the CSV required several tables with relationships to be 
> populated. One could
> certainly abstract this out into an api, but that can have impacts on 
> performance for large
> batch processing if you are creating parameters for every insert rather than 
> reusing them.
>
> In simple cases, the code is trivial but in this example, it looks terrible 
> given the number of
> Command instances...

.NET's handling of SQL parameter objects is horribly verbose.

If you had access to the SQLite C API, you could write a helper function
that automatically created all the parameter objects for you.  But even
so, you can write a helper function with a list of parameter names:

  var attributeCommand = CreateCommandHelperFunction(
connection,
@"INSERT INTO Attribute
  (Type, Value, AccountId)
  VALUES
  (@Type, @Value, @AccountId)",
"@Type", "@Value", "@AccountId"
  );

If the returned object is your own wrapper, you can also make the
parameter binding easier; something like this:

  attributeCommand.bindParameter(1,type);   // or:
  attributeCommand.bindParameter("@Value", value);


Regards,
Clemens
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users