1+ Public Class ProviderResource
2+ Inherits Databasic.ProviderResource
3+
4+ Public Overrides Function GetTableColumns(table As String , connection As Databasic.Connection) As Dictionary( Of String , Boolean )
5+ Dim schema = "dbo"
6+ Dim dotPos = table.IndexOf( "."c ) ' ignore (screw) here all tables with dot contained in name, only realy dummy developers can use that form...:-(
7+ If dotPos > - 1 Then
8+ schema = table.Substring( 0 , dotPos)
9+ table = table.Substring(dotPos + 1 )
10+ End If
11+ Return Databasic.Statement.Prepare( "
12+ SELECT
13+ c.is_nullable,
14+ c.name
15+ FROM
16+ sys.columns AS c
17+ WHERE
18+ c.object_id = (
19+ SELECT
20+ o.object_id
21+ FROM
22+ sys.objects AS o
23+ WHERE
24+ o.name = @table AND
25+ o.schema_id = (
26+ SELECT s.schema_id
27+ FROM sys.schemas AS s
28+ WHERE s.name = @schema
29+ )
30+ )
31+ ORDER BY
32+ c.column_id
33+ ", connection
34+ ).FetchAll( New With {
35+ .schema = schema,
36+ .table = table
37+ }).ToDictionary( Of String , Boolean )( "name" )
38+ End Function
39+
40+ Public Overrides Function GetLastInsertedId( ByRef transaction As Databasic.Transaction, Optional ByRef classMetaDescription As MetaDescription = Nothing ) As Object
41+ If classMetaDescription.Tables.Length > 0 Then
42+ Return Databasic.Statement.Prepare(
43+ "SELECT IDENT_CURRENT(@table)" , transaction
44+ ).FetchOne( New With {
45+ .table = classMetaDescription.Tables( 0 )
46+ }).ToInstance( Of Object )()
47+ Else
48+ Return Databasic.Statement.Prepare(
49+ "SELECT @@IDENTITY" , transaction
50+ ).FetchOne().ToInstance( Of Object )()
51+ End If
52+ End Function
53+
54+ 'Public Overrides Function GetAll(
55+ ' connection As Databasic.Connection,
56+ ' table As String,
57+ ' columns As String,
58+ ' Optional offset As Int64? = Nothing,
59+ ' Optional limit As Int64? = Nothing,
60+ ' Optional orderByStatement As String = ""
61+ ') As Databasic.Statement
62+ ' Dim sql = $"SELECT {columns} FROM {table}"
63+ ' offset = If(offset, 0)
64+ ' limit = If(limit, 0)
65+ ' If limit > 0 Then
66+ ' If connection.ProviderVersion.Major < 12 Then
67+ ' sql = $"SELECT {If(limit > 0, "TOP " + limit, "")} ____src.*
68+ ' INTO #result
69+ ' FROM (
70+ ' SELECT *, ROW_NUMBER() OVER (ORDER BY {orderByStatement}) AS ____rowNumber
71+ ' FROM {table}
72+ ' ) AS ____src
73+ ' WHERE ____src.____rowNumber > {offset}
74+ ' ORDER BY {orderByStatement}
75+ ' ALTER TABLE #result
76+ ' DROP COLUMN ____rowNumber
77+ ' SELECT * FROM #result
78+ ' DROP TABLE #result"
79+ ' Else
80+ ' sql += $" ORDER BY {orderByStatement} OFFSET {offset} ROWS"
81+ ' If limit > 0 Then sql += $" FETCH NEXT {limit} ROWS ONLY"
82+ ' End If
83+ ' End If
84+ ' Return Databasic.Statement.Prepare(sql, connection).FetchAll()
85+ 'End Function
86+
87+ End Class
0 commit comments