-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProviderResource.vb
More file actions
61 lines (57 loc) · 2.22 KB
/
ProviderResource.vb
File metadata and controls
61 lines (57 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Public Class ProviderResource
Inherits Databasic.ProviderResource
Public Overrides Function GetTableColumns(table As String, connection As Databasic.Connection) As Dictionary(Of String, Boolean)
Dim result As New Dictionary(Of String, Boolean)
Dim schema = "public"
Dim dotPos = table.IndexOf("."c) ' ignore (screw) here all tables with dot contained in name, only realy dummy developers can use that form...:-(
If dotPos > -1 Then
schema = table.Substring(0, dotPos)
table = table.Substring(dotPos + 1)
End If
Dim rawData As Dictionary(Of String, String) = Databasic.Statement.Prepare("
SELECT
c.is_nullable,
c.column_name
FROM
information_schema.columns c
WHERE
c.table_schema = @schema AND
c.table_catalog = @database AND
c.table_name = @table
ORDER BY
c.ordinal_position ASC",
connection
).FetchAll(New With {
.schema = schema,
.database = connection.Provider.Database,
.table = table
}).ToDictionary(Of String, String)("column_name")
Dim columnCouldBenull As Boolean
For Each item In rawData
columnCouldBenull = item.Value.ToUpper().IndexOf("NO") = -1
result.Add(item.Key, columnCouldBenull)
Next
Return result
End Function
Public Overrides Function GetLastInsertedId(ByRef transaction As Databasic.Transaction, Optional ByRef classMetaDescription As MetaDescription = Nothing) As Object
' https://stackoverflow.com/questions/2944297/postgresql-function-for-last-inserted-id
Return Databasic.Statement.Prepare("SELECT LAST_INSERT_ID()", transaction).FetchOne().ToInstance(Of Object)()
End Function
'Public Overrides Function GetAll(
' connection As Databasic.Connection,
' columns As String,
' table As String,
' Optional offset As Int64? = Nothing,
' Optional limit As Int64? = Nothing,
' Optional orderByStatement As String = ""
' ) As Databasic.Statement
' Dim sql = $"SELECT {columns} FROM {table}"
' offset = If(offset, 0)
' limit = If(limit, 0)
' If limit > 0 Then
' sql += If(orderByStatement.Length > 0, " ORDER BY " + orderByStatement, "") +
' $" LIMIT {If(limit = 0, "18446744073709551615", limit.ToString())} OFFSET {offset}"
' End If
' Return Databasic.Statement.Prepare(sql, connection).FetchAll()
'End Function
End Class