11Public Class ProviderResource
22 Inherits Databasic.ProviderResource
33
4- ' TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO
5-
6- Public Overrides Function GetTableColumns(table As String , connection As Databasic.Connection) As Dictionary( Of String , Boolean )
7- Dim result As New Dictionary( Of String , Boolean )
8- Dim rawData As Dictionary( Of String , String ) = Databasic.Statement.Prepare( "
4+ Public Overrides Function GetTableColumns(table As String , connection As Databasic.Connection) As Dictionary( Of String , Boolean )
5+ Throw New NotImplementedException()
6+ Dim result As New Dictionary( Of String , Boolean )
7+ Dim rawData As Dictionary( Of String , String ) = Databasic.Statement.Prepare( "
98 SELECT
109 c.IS_NULLABLE,
1110 c.COLUMN_NAME
1716 ORDER BY
1817 c.ORDINAL_POSITION
1918 ", connection
20- ).FetchAll( New With {
21- .database = connection.Provider.Database,
22- .table = table
23- }).ToDictionary( Of String , String )( "COLUMN_NAME" )
24- Dim columnCouldBenull As Boolean
25- For Each item In rawData
26- columnCouldBenull = item.Value.ToUpper().IndexOf( "NO" ) = - 1
27- result.Add(item.Key, columnCouldBenull)
28- Next
29- Return result
30- End Function
19+ ).FetchAll( New With {
20+ .database = connection.Provider.Database,
21+ .table = table
22+ }).ToDictionary( Of String , String )( "COLUMN_NAME" )
23+ Dim columnCouldBenull As Boolean
24+ For Each item In rawData
25+ columnCouldBenull = item.Value.ToUpper().IndexOf( "NO" ) = - 1
26+ result.Add(item.Key, columnCouldBenull)
27+ Next
28+ Return result
29+ End Function
3130
32- Public Overrides Function GetLastInsertedId( ByRef transaction As Databasic.Transaction, Optional ByRef classMetaDescription As MetaDescription = Nothing ) As Object
33- Return Databasic.Statement.Prepare( "SELECT LAST_INSERT_ID()" , transaction).FetchOne().ToInstance( Of Object )()
34- End Function
31+ Public Overrides Function GetLastInsertedId( ByRef transaction As Databasic.Transaction, Optional ByRef classMetaDescription As MetaDescription = Nothing ) As Object
32+ Throw New NotImplementedException()
33+ Return Databasic.Statement.Prepare( "SELECT LAST_INSERT_ID()" , transaction).FetchOne().ToInstance( Of Object )()
34+ End Function
3535
36- 'Public Overrides Function GetAll(
37- ' connection As Databasic.Connection,
38- ' columns As String,
39- ' table As String,
40- ' Optional offset As Int64? = Nothing,
41- ' Optional limit As Int64? = Nothing,
42- ' Optional orderByStatement As String = ""
43- ' ) As Databasic.Statement
44- ' Dim sql = $"SELECT {columns} FROM {table}"
45- ' offset = If(offset, 0)
46- ' limit = If(limit, 0)
47- ' If limit > 0 Then
48- ' sql += If(orderByStatement.Length > 0, " ORDER BY " + orderByStatement, "") +
49- ' $" LIMIT {If(limit = 0, "18446744073709551615", limit.ToString())} OFFSET {offset}"
50- ' End If
51- ' Return Databasic.Statement.Prepare(sql, connection).FetchAll()
52- 'End Function
36+ 'Public Overrides Function GetAll(
37+ ' connection As Databasic.Connection,
38+ ' columns As String,
39+ ' table As String,
40+ ' Optional offset As Int64? = Nothing,
41+ ' Optional limit As Int64? = Nothing,
42+ ' Optional orderByStatement As String = ""
43+ ' ) As Databasic.Statement
44+ ' Dim sql = $"SELECT {columns} FROM {table}"
45+ ' offset = If(offset, 0)
46+ ' limit = If(limit, 0)
47+ ' If limit > 0 Then
48+ ' sql += If(orderByStatement.Length > 0, " ORDER BY " + orderByStatement, "") +
49+ ' $" LIMIT {If(limit = 0, "18446744073709551615", limit.ToString())} OFFSET {offset}"
50+ ' End If
51+ ' Return Databasic.Statement.Prepare(sql, connection).FetchAll()
52+ 'End Function
5353
54- Public Overridable Function GetList(
55- conditionSqlStatement As String ,
56- conditionParams As Object ,
57- orderBySqlStatement As String ,
58- offset As Int64?,
59- limit As Int64?,
60- connectionOrTransaction As Object ,
61- ByRef classMetaDescription As MetaDescription
62- ) As Databasic.Statement
63- Dim columns As String = String .Join( "," , Databasic.ProviderResource.ColumnsArray(classMetaDescription.ClassType, 0 ))
64- Dim sql As String = $"SELECT {columns} FROM {ActiveRecord.Resource.Table(classMetaDescription)}"
65- Dim params As Object = Nothing
66- If Not String .IsNullOrEmpty(conditionSqlStatement) Then
67- sql += " WHERE " + conditionSqlStatement
68- params = conditionParams
69- End If
70- If Not String .IsNullOrEmpty(orderBySqlStatement) Then
71- sql += " ORDER BY " + orderBySqlStatement
72- End If
73- If offset.HasValue Then
74- ' offset a number, but could be 0, limit is unknown
75- sql += $" LIMIT {If(Not limit.HasValue, "18446744073709551615", limit.ToString())} OFFSET {offset}"
76- ElseIf limit.HasValue And limit > 0 Then
77- ' offset is null, limit is a number, but could be 0
78- sql += $" LIMIT {limit.ToString()}"
79- End If
80- Return Databasic.Statement.Prepare(sql, connectionOrTransaction).FetchAll(params)
81- End Function
54+ Public Overridable Function GetList(
55+ conditionSqlStatement As String ,
56+ conditionParams As Object ,
57+ orderBySqlStatement As String ,
58+ offset As Int64?,
59+ limit As Int64?,
60+ connectionOrTransaction As Object ,
61+ ByRef classMetaDescription As MetaDescription
62+ ) As Databasic.Statement
63+ Throw New NotImplementedException()
64+ Dim columns As String = String .Join( "," , Databasic.ProviderResource.ColumnsArray(classMetaDescription.ClassType, 0 ))
65+ Dim sql As String = $"SELECT {columns} FROM {ActiveRecord.Resource.Table(classMetaDescription)}"
66+ Dim params As Object = Nothing
67+ If Not String .IsNullOrEmpty(conditionSqlStatement) Then
68+ sql += " WHERE " + conditionSqlStatement
69+ params = conditionParams
70+ End If
71+ If Not String .IsNullOrEmpty(orderBySqlStatement) Then
72+ sql += " ORDER BY " + orderBySqlStatement
73+ End If
74+ If offset.HasValue Then
75+ ' offset a number, but could be 0, limit is unknown
76+ sql += $" LIMIT {If(Not limit.HasValue, "18446744073709551615", limit.ToString())} OFFSET {offset}"
77+ ElseIf limit.HasValue And limit > 0 Then
78+ ' offset is null, limit is a number, but could be 0
79+ sql += $" LIMIT {limit.ToString()}"
80+ End If
81+ Return Databasic.Statement.Prepare(sql, connectionOrTransaction).FetchAll(params)
82+ End Function
8283
8384End Class
0 commit comments