Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Database DBMS__Virtual_Machine  

DBMS__Virtual_Machine

DBMS__Virtual_Machine

Category: Database
By : Very Keynes
Created: 2010-11-18 Edited: 2010-11-18
Worlds: Second Life

the Zip file

Download all files for DBMS__Virtual_Machine
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. DBMS__Virtual_Machine_1.lsl
1 //Very Keynes - 2008 - 2009
2 //
3 // Version: OpenSimulator Server 0.6.1.7935 (interface version 2)
4 //
5 // 2009-01-06, 19:30 GMT
6 //
7 //------------------Begin VK-DBMS-VM----------------------------\\
8 //--------------------Introduction------------------------------\\
9 //
10 // Very Keynes - DBMS - Virtual Machine
11 //
12 // Implements a core set of registers and root functions
13 // to create and manage multi-table database structures as
14 // an LSL list. Although intended to under pin higher level
15 // database management tools such as VK-SQL it is usable as
16 // a small footprint database facility for system level
17 // applications.
18 //
19 //
20 // Naming Conventions and Code Style
21 //
22 // This Code is intended to be included as a header to user generated
23 // code. As such it's naming convention was selected so that it would
24 // minimise the possibility of duplicate names in the user code portion
25 // of the application. Exposed Functions and Variables are prefixed db.
26 //
27 // A full User Guide and Tutorial is availible at this URL:
28 //
29 // http://docs.google.com/Doc?id=d79kx35_26df2pbbd8
30 //
31 //
32 // Table Control Registers
33 //
34 integer th_; // Table Handle / Index Pointer
35 integer tc_; // Columns in Active Table
36 integer tr_; // Rows in Active Table
37 integer ts_; // Active Table Start Address
38 //
39 list _d_ = []; // Database File
40 list _i_ = [0]; // Index File
41 //
42 // Exposed Variables
43 //
44 integer dbIndex; // Active Row Table Pointer
45 list dbRow; // User Scratch List
46 string dbError; // System Error String
47 //
48 // Temporary / Working Variables
49 //
50 integer t_i;
51 string t_s;
52 float t_f;
53 list t_l;
54 //
55 // System Functions
56 //
57 string dbCreate(string tab, list col)
58 {
59 if(dbOpen(tab))
60 {
61 dbError = tab + " already exists";
62 return "";
63 }
64 tc_ = llGetListLength(col);
65 _i_ += [tab, tc_, 0, 0, 0];
66 th_= 0;
67 dbOpen(tab);
68 dbInsert(col);
69 return tab;
70 }
71
72
73 integer dbCol(string col)
74 {
75 return llListFindList(dbGet(0), [_trm(col)]);
76 }
77
78
79 integer dbDelete(integer ptr)
80 {
81 if(ptr > 0 && ptr < tr_)
82 {
83 t_i = ts_ + tc_ * ptr;
84 _d_ = llDeleteSubList(_d_, t_i, t_i + tc_ - 1);
85 --tr_;
86 return tr_ - 1;
87 }
88 else
89 {
90 dbError = (string)ptr + " is outside the Table Bounds";
91 return FALSE;
92 }
93 }
94
95
96 integer dbDrop(string tab)
97 {
98 t_i = llListFindList(_i_, [tab]);
99 if(-1 != t_i)
100 {
101 dbOpen(tab);
102 _d_ = llDeleteSubList(_d_, ts_, ts_ + tc_ * tr_ - 1);
103 _i_ = llDeleteSubList(_i_, th_, th_ + 4);
104 th_= 0;
105 return TRUE;
106 }
107 else
108 {
109 dbError = tab + " : Table name not recognised";
110 return FALSE;
111 }
112 }
113
114
115 integer dbExists(list cnd)
116 {
117 for(dbIndex = tr_ - 1 ; dbIndex > 0 ; --dbIndex)
118 {
119 if(dbTest(cnd)) return dbIndex;
120 }
121 return FALSE;
122 }
123
124
125 list dbGet(integer ptr)
126 {
127 if(ptr < tr_ && ptr >= 0)
128 {
129 t_i = ts_ + tc_ * ptr;
130 return llList2List(_d_, t_i, t_i + tc_ - 1);
131 }
132 else
133 {
134 dbError = (string) ptr + " is outside the Table Bounds";
135 return [];
136 }
137 }
138
139
140 integer _idx(integer hdl)
141 {
142 return (integer)llListStatistics(6, llList2ListStrided(_i_, 0, hdl, 5));
143 }
144
145
146 integer dbInsert(list val)
147 {
148 if(llGetListLength(val) == tc_)
149 {
150 dbIndex = tr_++;
151 _d_ = llListInsertList(_d_, val, ts_ + tc_ * dbIndex);
152 return dbIndex;
153 }
154 else
155 {
156 dbError = "Insert Failed - too many or too few Columns specified";
157 return FALSE;
158 }
159 }
160
161
162 integer dbOpen(string tab)
163 {
164 if(th_)
165 {
166 _i_ = llListReplaceList(_i_, [tr_, dbIndex, tc_ * tr_], th_ + 2, th_ + 4);
167 }
168 t_i = llListFindList(_i_, [tab]);
169 if(-1 == t_i) //if tab does not exist abort
170 {
171 dbError = tab + " : Table name not recognised";
172 return FALSE;
173 }
174 else if(th_ != t_i)
175 {
176 th_ = t_i++;
177 ts_ = _idx(th_);
178 tc_ = llList2Integer(_i_, t_i++);
179 tr_ = llList2Integer(_i_, t_i++);
180 dbIndex = llList2Integer(_i_, t_i);
181 }
182 return tr_ - 1;
183 }
184
185
186 integer dbPut(list val)
187 {
188 if(llGetListLength(val) == tc_)
189 {
190 t_i = ts_ + tc_ * dbIndex;
191 _d_ = llListReplaceList(_d_, val, t_i, t_i + tc_ - 1);
192 return dbIndex;
193 }
194 else
195 {
196 dbError = "Update Failed - too many or too few Columns specified";
197 return FALSE;
198 }
199 }
200
201
202 integer dbTest(list cnd)
203 {
204 if(llGetListEntryType(cnd,2) >= 3)
205 {
206 t_s = llList2String(dbGet(dbIndex), dbCol(llList2String(cnd, 0)));
207 if("==" == llList2String(cnd, 1)){t_i = t_s == _trm(llList2String(cnd, 2));}
208 else if("!=" == llList2String(cnd, 1)){t_i = t_s != _trm(llList2String(cnd, 2));}
209 else if("~=" == llList2String(cnd, 1))
210 {t_i = !(llSubStringIndex(llToLower(t_s), llToLower(_trm(llList2String(cnd, 2)))));}
211 }
212 else
213 {
214 t_f = llList2Float(dbGet(dbIndex), dbCol(llList2String(cnd, 0)));
215 t_s = llList2String(cnd, 1);
216 if("==" == t_s){t_i = t_f == llList2Float(cnd, 2);}
217 else if("!=" == t_s){t_i = t_f != llList2Float(cnd, 2);}
218 else if("<=" == t_s){t_i = t_f <= llList2Float(cnd, 2);}
219 else if(">=" == t_s){t_i = t_f >= llList2Float(cnd, 2);}
220 else if("<" == t_s){t_i = t_f < llList2Float(cnd, 2);}
221 else if(">" == t_s){t_i = t_f > llList2Float(cnd, 2);}
222 }
223 if(t_i) return dbIndex;
224 else return FALSE;
225 }
226
227
228 string _trm(string val)
229 {
230 return llStringTrim(val, STRING_TRIM);
231 }
232
233
234 dbTruncate(string tab)
235 {
236 dbIndex = dbOpen(tab);
237 while(dbIndex > 0) dbDelete(dbIndex--);
238 }
239
240
241 dbSort(integer dir)
242 {
243 t_i = ts_ + tc_;
244 _d_ = llListReplaceList(_d_, llListSort(llList2List(_d_, t_i, t_i + tc_ * tr_ - 2), tc_, dir), t_i, t_i + tc_ * tr_ - 2);
245 }
246
247
248 float dbFn(string fn, string col)
249 {
250 t_i = ts_ + tc_;
251 t_l = llList2List(_d_, t_i, t_i + tc_ * tr_ - 2);
252 if(dbCol(col) != 0) t_l = llDeleteSubList(t_l, 0, dbCol(col) - 1);
253 return llListStatistics(llSubStringIndex("ramimaavmedesusqcoge", llGetSubString(llToLower(fn),0,1)) / 2,
254 llList2ListStrided(t_l, 0, -1, tc_));
255 }
256 //
257 //--------------------------- End VK-DBMS-VM ---------------------------\\
258 //
259 default
260 {
262 {
263 dbCreate("DMSolo", ["uuid", "inst", "anim", "mode"]);
264 dbInsert([llGetOwner(), llKey2Name(llGetOwner()), "testing", 1234]);
265 }
266
267 touch_start(integer total_number)
268 {
269 if(dbExists(["uuid", "==", llDetectedKey(0)]))
270 {
271 dbRow = dbGet(dbIndex);
272 llSay(0, "Hello " + llList2String(dbRow, 1));
273 }
274 else llSay(0, "Sorry you are not on my list");
275 }
276 }

Back to the Best Free Tools in Second Life and OpenSim.