-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.vala
132 lines (127 loc) · 3.43 KB
/
test.vala
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using GLib;
using SinticBolivia;
using SinticBolivia.Classes;
using SinticBolivia.Database;
namespace Test
{
public class SBApplication : Entity
{
public long id {get; set;}
public string name {get; set;}
public string key {get; set;}
public string description {get; set;}
construct
{
//Object(table: "applications", primary_key: "id");
this._table = "applications";
this._primary_key = "id";
}
public SBApplication()
{
}
}
}
public void send_email()
{
var smtp = new SBSmtpClient()
{
server = "mail.sinticbolivia.net",
port = 25
};
smtp.open(SmtpConnectionSecurity.SECURITY_STARTTLS);
smtp.auth("[email protected]", "JnmsAKmu4k5I", SmtpAuthMethod.AUTH_LOGIN);
smtp.addFrom("[email protected]", "Test SinticLibrary");
smtp.addAddress("[email protected]", "%s %s".printf("Pepito", "Perez"));
//smtp.addAttachmentFile(this.printInvoice(invoice, false));
//smtp.addAttachmentData("invoice-%s.xml".printf(invoice.invoice_number.to_string()), siatInvoice.toXml().data);
smtp.send("Test subject", "Test Message body");
smtp.close();
}
public void show_processor()
{
var os = new SBOS();
string psn = os.GetProcessorSN();
stdout.printf("Processor S/N: %s\n", psn);
}
public SBDatabase get_db_instance() throws SBDatabaseException
{
SBFactory.config = new SBConfig("config.xml", "config");
var dbh = SBFactory.getDbh();
return dbh;
}
public void test_postgres()
{
try
{
var dbh = get_db_instance();
//dbh.Query("SELECT * FROM mb_invoices");
//dbh.Execute("BEGIN");
//dbh.Execute("DECLARE myusers CURSOR FOR SELECT * FROM users;");
//res = conn.exec ("FETCH ALL in myusers");
//var items = dbh.GetResults("FETCH ALL in myusers;");
var items = dbh.GetResults("SELECT * FROM applications");
foreach(var row in items)
{
stdout.printf("Name: %s\n", row.Get("name"));
}
//dbh.Execute("END");
}
catch(SBDatabaseException e)
{
stderr.printf("ERROR: %s\n", e.message);
}
}
public void test_entity()
{
get_db_instance();
size_t size;
var a = new Test.SBApplication();
//stdout.printf(a.get_table());
var app = Entity.read<Test.SBApplication>(5);
stdout.printf("Name: %s\nCreation Date: %s\n", app.name, app.creation_date.format("%Y-%m-%d %H:%M:%S"));
stdout.printf(Json.gobject_to_data(app, out size));
}
public void test_query()
{
var builder = new SBDBQuery();
builder
.select("id,application_id,product_id,name,SUM(sp.price)")
.from("subscriptions_plans sp")
.where()
.equals("id", 1)
.or()
.greater_than("application_id", 5)
.and()
.where_group((qb) =>
{
qb.where("name", "like", "x")
.or()
.where("TRIM(sp.description)", "<>", "''")
;
})
.and()
.in_array("status", new string[]{"disabled", "enabled"})
.and()
.is_null("description")
.order_by("id");
stdout.printf("BUILT QUERY:\n%s\n", builder.sql());
}
public int main(string[] args)
{
/*
string pattern = """(?P<function>\w+)\s*\((?P<column>[0-1A-Za-z_\.]+)\)(?P<aux>.*)""";
var r = new Regex(pattern);
MatchInfo info;
if( r.match("SUM(p.price) AS price", RegexMatchFlags.ANCHORED, out info) )
{
print("FUNCTION: %s\nCOLUNN: %s\nAUX: %s\n", info.fetch_named("function"), info.fetch_named("column"), info.fetch_named("aux"));
}
*/
send_email();
//get_db_instance();
//show_processor();
//test_postgres();
//test_entity();
//test_query();
return 0;
}