-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrappers.lua
217 lines (140 loc) · 4.6 KB
/
wrappers.lua
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
--[[
File: Wrapper Functions
This file is to offer a little bit of coherence to our scripts. Since we'll be dealing with all
sorts of environments and setups, anything we need that might vary is defined as a wrapper stub
below. All of these functions should be defined for every application implementation.
]]
--- Module: wrappers
module( "wrappers", package.seeall )
--- Group: SQL Wrapper Functions
--[[
Function: FormatAndEscapeData
Formats and escapes data from lua to be appropriate for use in SQL. This function must quote
and escape strings as well as handle nil and numbers. For numbers, you probably want to pass it
right back as a string. For nil, you probably want to return "NULL".
Parameters:
data - The data that can be a *string*, *number*, or *nil*. Any other type is an error
condition.
Returns:
The *string* of the formatted and escaped data.
Revisions:
v1.00 - Initial.
]]
function FormatAndEscapeData( data )
error( ErrorMessages.NotImplemented, 2 )
end
--[[
Function: Execute
Execute given statement on the database. Note that we assume that there is only one database,
and we're automatically connected to it.
Parameters:
database_type - The *database type* to execute this statement on. See
<otlib.DatabaseTypes>.
statement - The *string* to execute on the database. If the statement doesn't execute
properly, raise an error.
key_types - An *optional table* indexed by row-key string name with lua string type values
(IE, "number"). This is here in case you're dealing with a poor SQL implementation and
need to convert datatypes yourself.
Returns:
*Nil* if it wasn't a select operation, a *list table* of selected data otherwise.
Revisions:
v1.00 - Initial.
]]
function Execute( database_type, statement, key_types )
error( ErrorMessages.NotImplemented, 2 )
end
--[[
Function: BeginTransaction
If the SQL implementation allows it, start a transaction. Otherwise, implement this as an empty
function.
Revisions:
v1.00 - Initial.
]]
function BeginTransaction( database_type )
error( ErrorMessages.NotImplemented, 2 )
end
--[[
Function: EndTransaction
If the SQL implementation allows it, end a transaction. Otherwise, implement this as an empty
function.
Revisions:
v1.00 - Initial.
]]
function EndTransaction( database_type )
error( ErrorMessages.NotImplemented, 2 )
end
--[[
Function: BeginTransaction
Get the number of affected rows from the last statement executed.
Returns:
The *number* of rows affected.
Revisions:
v1.00 - Initial.
]]
function AffectedRows()
error( ErrorMessages.NotImplemented, 2 )
end
--- Group: File Wrapper Functions
--[[
Function: FileExists
Check to see if a file or folder exists.
Parameters:
file_path - The file path *string*.
Returns:
A *boolean* indicating whether or not the file or folder exists.
Revisions:
v1.00 - Initial.
]]
function FileExists( file_path )
error( ErrorMessages.NotImplemented, 2 )
end
--[[
Function: FileRead
Read a file.
Parameters:
file_path - The file path *string*.
Returns:
The *string* of the file contents. Returns an empty string if the file doesn't exists.
Revisions:
v1.00 - Initial.
]]
function FileRead( file_path )
error( ErrorMessages.NotImplemented, 2 )
end
--[[
Function: FileWrite
Write to a file. Should clear the contents of any existing file first.
Parameters:
file_path - The file path *string*.
data - The *string* to write to the file.
Revisions:
v1.00 - Initial.
]]
function FileWrite( file_path, data )
error( ErrorMessages.NotImplemented, 2 )
end
--[[
Function: FileDelete
Delete a file or folder. Should only delete empty directories.
Parameters:
file_path - The file or folder path *string*.
Revisions:
v1.00 - Initial.
]]
function FileDelete( file_path )
error( ErrorMessages.NotImplemented, 2 )
end
--- Group: Command Wrappers
-- TODO
function AddConsoleCommand( command_name, callback, access, ... )
error( ErrorMessages.NotImplemented, 2 )
end
function AddSayCommand( command_name, callback, access, ... )
error( ErrorMessages.NotImplemented, 2 )
end
function RemoveConsoleCommand( command_name )
error( ErrorMessages.NotImplemented, 2 )
end
function RemoveSayCommand( command_name )
error( ErrorMessages.NotImplemented, 2 )
end