-
Notifications
You must be signed in to change notification settings - Fork 1
/
Module1.bas
80 lines (71 loc) · 2.92 KB
/
Module1.bas
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Attribute VB_Name = "Module1"
Option Explicit
Public cn As New ADODB.Connection
Dim vConnectionString As String
Public Sub Main()
Dim objArray As Variant
Dim objClient As clsClient
Dim objEmployee As clsEmployee
Dim dictParams As New Dictionary
Dim i As Long
vConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;User ID=postgres;Data Source=PostConnection"
cn.ConnectionString = vConnectionString
cn.Open
cn.Execute "create table if not exists client(id serial primary key, name text,age int,email text);"
cn.Execute "create table if not exists employee(id serial primary key, name text,position text,email text);"
'cn.Execute "insert into client values(default,'Jhon',28,'jhon@example.com')"
'cn.Execute "insert into client values(default,'Mary',31,'mary@example.com')"
'cn.Execute "insert into employee values(default,'Jhon','CTO','mary@example.com')"
'cn.Execute "insert into employee values(default,'Mary','CFO','mary@example.com')"
Set objClient = GetCreate(C_clsClient)
objClient.ID = 1
objClient.Name = "Updated client"
objClient.Age = 35
objClient.Email = "client@example.com"
'Save the client (insert or update based on primary key)
If objClient.AsIBaseClass.Save Then
Debug.Print "Client saved successfully!"
Else
Debug.Print "Error saving client."
End If
objArray = DataBaseSelectSQL(C_clsClient, "select * from client")
Debug.Print "Count:" & UBound(objArray)
For i = 1 To UBound(objArray)
Set objClient = objArray(i)
Debug.Print "ID:" & objClient.ID
Debug.Print "Name:" & objClient.Name
Debug.Print "Age:" & objClient.Age
Debug.Print "Email:" & objClient.Email
Debug.Print ""
Debug.Print ""
Next i
Dim params As New clsParams
params.Add "name", "%New%", "ilike"
' params.Add "id", 6
objArray = DataBaseSelect(C_clsClient, params)
If HasValues(objArray) Then
Debug.Print "Count:" & UBound(objArray)
For i = 1 To UBound(objArray)
Set objClient = objArray(i)
Debug.Print "ID:" & objClient.ID
Debug.Print "Name:" & objClient.Name
Debug.Print "Age:" & objClient.Age
Debug.Print "Email:" & objClient.Email
Debug.Print "Errors:"; objClient.AsIBaseClass.CheckErrors
Debug.Print ""
Next i
End If
objArray = DataBaseSelectSQL(C_clsEmployee, "select * from employee")
If HasValues(objArray) Then
Debug.Print "Count:" & UBound(objArray)
For i = 1 To UBound(objArray)
Set objEmployee = objArray(i)
Debug.Print "ID:" & objEmployee.ID
Debug.Print "Name:" & objEmployee.Name
Debug.Print "Position:" & objEmployee.Position
Debug.Print "Email:" & objEmployee.Email
Debug.Print ""
Debug.Print ""
Next i
End If
End Sub