summary refs log tree commit diff stats
path: root/lib/impure/db_mysql.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <ar@kimeta.de>2014-04-10 01:47:20 +0200
committerAndreas Rumpf <ar@kimeta.de>2014-04-10 01:47:20 +0200
commitdcfc7a8896166563f6fd80fbab81bc50e0b5a217 (patch)
tree4a247ec2d64bafec53e5ab24b0fda89642908a07 /lib/impure/db_mysql.nim
parenta86c774932afd8b6782df1925837df9df04ef381 (diff)
parent8b82004359b8d852fa0107d79cc78b21eb35c028 (diff)
downloadNim-dcfc7a8896166563f6fd80fbab81bc50e0b5a217.tar.gz
resolved conflict
Diffstat (limited to 'lib/impure/db_mysql.nim')
-rw-r--r--lib/impure/db_mysql.nim36
1 files changed, 21 insertions, 15 deletions
diff --git a/lib/impure/db_mysql.nim b/lib/impure/db_mysql.nim
index 91cf8a5eb..32cda3e4d 100644
--- a/lib/impure/db_mysql.nim
+++ b/lib/impure/db_mysql.nim
@@ -65,7 +65,7 @@ proc dbFormat(formatstr: TSqlQuery, args: varargs[string]): string =
     else: 
       add(result, c)
   
-proc TryExec*(db: TDbConn, query: TSqlQuery, args: varargs[string, `$`]): bool {.
+proc tryExec*(db: TDbConn, query: TSqlQuery, args: varargs[string, `$`]): bool {.
   tags: [FReadDB, FWriteDb].} =
   ## tries to execute the query and returns true if successful, false otherwise.
   var q = dbFormat(query, args)
@@ -75,7 +75,7 @@ proc rawExec(db: TDbConn, query: TSqlQuery, args: varargs[string, `$`]) =
   var q = dbFormat(query, args)
   if mysql.RealQuery(db, q, q.len) != 0'i32: dbError(db)
 
-proc Exec*(db: TDbConn, query: TSqlQuery, args: varargs[string, `$`]) {.
+proc exec*(db: TDbConn, query: TSqlQuery, args: varargs[string, `$`]) {.
   tags: [FReadDB, FWriteDb].} =
   ## executes the query and raises EDB if not successful.
   var q = dbFormat(query, args)
@@ -87,10 +87,10 @@ proc newRow(L: int): TRow =
   
 proc properFreeResult(sqlres: mysql.PRES, row: cstringArray) =  
   if row != nil:
-    while mysql.FetchRow(sqlres) != nil: nil
+    while mysql.FetchRow(sqlres) != nil: discard
   mysql.FreeResult(sqlres)
   
-iterator FastRows*(db: TDbConn, query: TSqlQuery,
+iterator fastRows*(db: TDbConn, query: TSqlQuery,
                    args: varargs[string, `$`]): TRow {.tags: [FReadDB].} =
   ## executes the query and iterates over the result dataset. This is very 
   ## fast, but potenially dangerous: If the for-loop-body executes another
@@ -126,7 +126,7 @@ proc getRow*(db: TDbConn, query: TSqlQuery,
         add(result[i], row[i])
     properFreeResult(sqlres, row)
 
-proc GetAllRows*(db: TDbConn, query: TSqlQuery, 
+proc getAllRows*(db: TDbConn, query: TSqlQuery, 
                  args: varargs[string, `$`]): seq[TRow] {.tags: [FReadDB].} =
   ## executes the query and returns the whole result dataset.
   result = @[]
@@ -145,12 +145,12 @@ proc GetAllRows*(db: TDbConn, query: TSqlQuery,
       inc(j)
     mysql.FreeResult(sqlres)
 
-iterator Rows*(db: TDbConn, query: TSqlQuery, 
+iterator rows*(db: TDbConn, query: TSqlQuery, 
                args: varargs[string, `$`]): TRow {.tags: [FReadDB].} =
   ## same as `FastRows`, but slower and safe.
   for r in items(GetAllRows(db, query, args)): yield r
 
-proc GetValue*(db: TDbConn, query: TSqlQuery, 
+proc getValue*(db: TDbConn, query: TSqlQuery, 
                args: varargs[string, `$`]): string {.tags: [FReadDB].} = 
   ## executes the query and returns the first column of the first row of the
   ## result dataset. Returns "" if the dataset contains no rows or the database
@@ -160,7 +160,7 @@ proc GetValue*(db: TDbConn, query: TSqlQuery,
     result = row[0]
     break
 
-proc TryInsertID*(db: TDbConn, query: TSqlQuery, 
+proc tryInsertId*(db: TDbConn, query: TSqlQuery, 
                   args: varargs[string, `$`]): int64 {.tags: [FWriteDb].} =
   ## executes the query (typically "INSERT") and returns the 
   ## generated ID for the row or -1 in case of an error.
@@ -170,14 +170,14 @@ proc TryInsertID*(db: TDbConn, query: TSqlQuery,
   else:
     result = mysql.InsertId(db)
   
-proc InsertID*(db: TDbConn, query: TSqlQuery, 
+proc insertId*(db: TDbConn, query: TSqlQuery, 
                args: varargs[string, `$`]): int64 {.tags: [FWriteDb].} = 
   ## executes the query (typically "INSERT") and returns the 
   ## generated ID for the row.
   result = TryInsertID(db, query, args)
   if result < 0: dbError(db)
 
-proc ExecAffectedRows*(db: TDbConn, query: TSqlQuery, 
+proc execAffectedRows*(db: TDbConn, query: TSqlQuery, 
                        args: varargs[string, `$`]): int64 {.
                        tags: [FReadDB, FWriteDb].} = 
   ## runs the query (typically "UPDATE") and returns the
@@ -185,18 +185,24 @@ proc ExecAffectedRows*(db: TDbConn, query: TSqlQuery,
   rawExec(db, query, args)
   result = mysql.AffectedRows(db)
 
-proc Close*(db: TDbConn) {.tags: [FDb].} = 
+proc close*(db: TDbConn) {.tags: [FDb].} = 
   ## closes the database connection.
-  if db != nil: mysql.Close(db)
+  if db != nil: mysql.close(db)
 
-proc Open*(connection, user, password, database: string): TDbConn {.
+proc open*(connection, user, password, database: string): TDbConn {.
   tags: [FDb].} =
   ## opens a database connection. Raises `EDb` if the connection could not
   ## be established.
   result = mysql.Init(nil)
   if result == nil: dbError("could not open database connection") 
-  if mysql.RealConnect(result, "", user, password, database, 
-                       0'i32, nil, 0) == nil:
+  let
+    colonPos = connection.find(':')
+    host =        if colonPos < 0: connection
+                  else:            substr(connection, 0, colonPos-1)
+    port: int32 = if colonPos < 0: 0'i32
+                  else:            substr(connection, colonPos+1).parseInt.int32
+  if mysql.RealConnect(result, host, user, password, database, 
+                       port, nil, 0) == nil:
     var errmsg = $mysql.error(result)
     db_mysql.Close(result)
     dbError(errmsg)
0 committer hut <hut@lavabit.com> 2010-10-10 03:20:45 +0200 Tea, Earl Grey, Hot.' href='/akspecs/ranger/commit/CHANGELOG?id=cbcd332596c53b43c06206a35b7830223a0bf411'>cbcd3325 ^
90018274 ^




cbcd3325 ^
95e021ae ^

c928a9eb ^
95e021ae ^
cbcd3325 ^
95e021ae ^















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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154