Comments (18)
I was already essentially doing this in the SqlCommandTP work I recently did, using a SP developed developed in-house at the shop I'm contracting to. Would really like to know what the most efficient way to do this is, as it is a very common requirement. I'm looking for execution speed low resource usage on the server.
from fsharp.data.sqlclient.
Can you post some sample code?
from fsharp.data.sqlclient.
[<Literal>]
let sqlCity = @"SELECT TOP (@categoryLimit) city FROM (
SELECT DISTINCT city
FROM tbQuickLocCount WITH (NOLOCK)
WHERE
city LIKE @startsWith
AND locType = 'City'
AND ownerID IN (select * from dbo.ConvertCSVToTableOfInts(@ownerIDList))
) as temp
ORDER BY city"
type QueryCity = SqlCommand<sqlCity, ConnectionStringName="staging", ConfigFile="AutoComplete.config">
let cityHits query ownnerCommaList entityID catLimit =
let cmdCity = QueryCity(connectionString = connectionString, startsWith = query + "%", ownerIDList = ownerCommaList, entit
from fsharp.data.sqlclient.
Taking a quick look at expected plan execution ConvertCSVToTableOfInts was 45% of total.
from fsharp.data.sqlclient.
My mistake, dbo.ConvertCSVToTableOfInts is a table-valued function.
from fsharp.data.sqlclient.
@jackfoxy No problem. It's still good. I understand what use case is. You would prefer to pass in ownerIDList as list of tuples or list of records, right?
from fsharp.data.sqlclient.
I can't think of a use case where I would want to pass in tuples or records. I have never known this use case to consume anything other than simple types, usually int32, sometimes string, but could be something else. And is there any reason to require a list? Why not allow any #seq for maximum flexibility?
I'm curious, what use case do you have in mind to parameterize for a list of tuples or records?
On a related note, I have not investigated, but I'm guessing you implement parameters as objects. Our DBA would disapprove. Especially in the case of varchar columns, SQL parameters should be strongly typed to the SQL DB type.
from fsharp.data.sqlclient.
sure #seq will be the best fit. In your example, don't you want to pass list of accounts (as #seq) instead of CSV string?
from fsharp.data.sqlclient.
Yes, I certainly would rather pass as #seq. I was just re-using a utility function built for interfacing to C# that is available at this shop, as I was in a hurry. I'm sure you will think of something much better. As I said before, this utility function consumes 45% of the estimated plan overhead on a simple query like the example.
from fsharp.data.sqlclient.
Btw, I forgot to comment on parameter types. We use SQL db type.So, nothing to worry about.
from fsharp.data.sqlclient.
The only way I've been able to discover a table-valued parameter is by passing it to a user-defined function or sproc:
CREATE TYPE myTableType
AS TABLE (myId int not null)
GO
CREATE FUNCTION myUDF (@p1 myTableType readonly)
RETURNS int
AS
BEGIN
DECLARE @Result int
SELECT @Result = (select top 1 * from @p1)
RETURN @Result
END
GO
sp_describe_undeclared_parameters @tsql=N'select dbo.myUDF(@x)'
This custom type can then be discovered, and a record built for it or something. I do see a use-case for something more complex than a seq of simple types. One could use a more complex type to insert a bunch of things in one go.
from fsharp.data.sqlclient.
I can have a go at it if no-one is working on it? Let me know.
from fsharp.data.sqlclient.
Sure, @rojepp. Go ahead. I was thinking that columns info can be retrieved something like:
select c.*
from sys.table_types as tt
inner join sys.columns as c
on tt.type_table_object_id = c.object_id
where tt.name = 'myTableType '
I think a lot of functionality can be reused
from fsharp.data.sqlclient.
@rojepp Create child type with same name as table type under providedCommanfType. Ideally choice between tuples and custom record type should be control by same param. So it will make sense rename to something like "RowsetType" instead of "ResultType".
from fsharp.data.sqlclient.
@dmitry-a-morozov I was thinking the same. :) It may be a few days before I have something working.
from fsharp.data.sqlclient.
@rojepp No problem. Take your time.
from fsharp.data.sqlclient.
@dmitry-a-morozov The parameter for choosing result type can also be DataTable. I can also imagine wanting DataTable for output but sending TVP as tuples. I suggest adding an optional parameter for TVP type, with a choice between tuples and records. Either that, or just start with tuples, and add records later if need arises. What do you think?
from fsharp.data.sqlclient.
Let's start with tuples only as input type for TVP.
from fsharp.data.sqlclient.
Related Issues (20)
- Dacpac support info HOT 3
- "F# Formatting" link is broken
- Can't build/run from the commandline, but can from Visual Studio 2019 HOT 2
- Question: Creating a provider without an access to DB HOT 3
- SqlEnumProvider breaks VS 2019 HOT 2
- Not platform detection Fable HOT 1
- Build is broken without full VS installation
- Fixed length binary columns in user defined table types fail when constructed HOT 8
- Cannot use User Defined Table Types with the SqlCommandProvider HOT 5
- .NET 6 support HOT 6
- One line summary of the bug HOT 2
- TVP Column Ordering is incorrect as of version 2.1.0
- Cannot use parameter name more than once in a script HOT 3
- System.Data.SqlClient is not supported on this platform. HOT 5
- Conversion failed when using User Defined Table Types HOT 1
- Any 2023 tricks for running on Windows? HOT 3
- NullReferenceException in SqlConnection.UseLocally HOT 1
- Support for 'Active Directory Interactive' authentication HOT 3
- dotnet SDK projects using FSharp.Core version 7.0.0 breaks at runtime HOT 3
- SQL LIKE operation doesn't recognize variable HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fsharp.data.sqlclient.