-
Notifications
You must be signed in to change notification settings - Fork 1
/
DBConnection.asv
83 lines (73 loc) · 2.38 KB
/
DBConnection.asv
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
classdef DBConnection
%UNTITLED Summary of this class goes here
% Detailed explanation goes here
% Currently supports SqlServer CE, MySql. Add more types, and handle
% fetch, close, exec methods.
properties
type;
conn_;
end
methods
function conn = DBConnection(type_, con)
conn.type = type_;
conn.conn_ = con;
if(conn.type == 1)
conn.conn_.Open();
end;
end;
function curs = exec(conn, sql)
if(conn.type == 0)
curs = exec(conn.conn_, sql);
else
curs = conn.conn_.CreateCommand();
curs.CommandText = sql;
curs = curs.ExecuteReader();
end;
end;
function close(conn)
if(conn.type == 0)
close(conn.conn_);
else
conn.conn_.Close();
end;
end
function retcurs = fetch(conn, curs)
if(conn.type == 0)
retcurs = fetch(curs);
else
i=1;
fc = curs.FieldCount;
A = cell(0);
while(curs.Read())
for j = 1:fc
k = j-1;
A(i,j) = {char(curs.GetValue(k))};
end;
i=i+1;
end;
retcurs.Data = A;
end;
end;
function retcurs = fetchl(conn, curs, limit)
if(conn.type == 0)
retcurs = fetch(curs, limit);
else
i=1;
fc = curs.FieldCount;
A = cell(0);
while(curs.Read())
if(i == limit)
break;
end;
for j = 1:fc
k = j-1;
if(strcmp('Int',curs.GetDataTypeName(k))
A(i,j) = {char(curs.GetValue(k))};
end;
i=i+1;
end;
retcurs.Data = A;
end;
end;
end
end