6 #include <attributes.h>
7 class mysql : public handle{
11 string describe() { return "MySQLHandle"; }
17 array tableinfo = oHandle->list_fields("ob_class", "obkeywords");
19 if ( sizeof(tableinfo) == 0 ) {
20 query = "alter table ob_class add (obkeywords text, obname text, obdescription text, obmimetype text, obversionof text)";
21 mixed err = catch(oHandle->big_query(query));
26 tableinfo = oHandle->list_fields("ob_class", "obdecoration");
27 if ( sizeof(tableinfo)==0 ) {
28 query = "alter table ob_class add (obdecoration text)";
29 oHandle->big_query(query);
30 MESSAGE("Modified Table ob_class with decoration column!");
34 int enable_decorations()
36 array tableinfo = oHandle->list_fields("ob_class", "obdecoration");
37 if ( sizeof(tableinfo)==0 )
43 mapping check_updates(object dbupdates, function update_classtableobject)
46 mapping resultmap = ([ ]);
48 object update = dbupdates->get_object_byname("classIndex");
49 if ( !objectp(update) ) {
50 string query = "create index class on ob_class (ob_class)";
51 catch(oHandle->big_query(query));
52 query = "create fulltext index obkeywords on ob_class (obkeywords)";
53 err=catch(oHandle->big_query(query));
54 resultmap->classIndex = "Successfully created index class on ob_class !\n";
57 FATAL("Database: Class-Update Failed:\n%O\n%O", err[0], err[1]);
58 resultmap->classIndex = sprintf("Failed:\n%O\n%O", err[0], err[1]);
62 update = dbupdates->get_object_byname("classKeywords");
63 if ( !objectp(update) ) {
65 object res = oHandle->big_query("select ob_id from ob_class where ob_class !='-'");
66 int sz = res->num_rows();
67 MESSAGE("Updating Objects in class table .... "+
68 "(might take a while: %d objects, ~%d minutes).....:\n ",
71 for ( int i = 0; i < sz; i++ ) {
72 int oid = (int)res->fetch_row()[0];
73 update_classtableobject(oid);
77 MESSAGE("** %d Objects updated in %d Seconds !", sz, time()-ts);
78 resultmap->classKeywords =
79 "Successfully installed keywords on ob_class !\n";
81 update = dbupdates->get_object_byname("binaryContent");
82 if ( !objectp(update) ) {
83 object res = oHandle->big_query("select ob_id from ob_class where ob_class !='-'");
84 int sz = res->num_rows();
86 MESSAGE("Updating doc_data table - setting binary content blobs, ~%d minutes",
89 res = oHandle->big_query("alter table doc_data modify rec_data blob");
90 resultmap->binaryContent = "Successfully updated CONTENT !\n";
91 MESSAGE("Installed binary-content Update in database in %d seconds",
95 object keywordUpdate = dbupdates->get_object_byname("keywords");
96 if ( !objectp(keywordUpdate) ) {
97 object attr = get_factory(CLASS_OBJECT)->describe_attribute(OBJ_KEYWORDS);
99 get_factory(CLASS_OBJECT)->register_attribute(attr);
100 array tables = oHandle->list_tables();
101 catch(oHandle->big_query("drop index obkeywords on ob_class"));
102 if ( search(tables, "mi_keyword_index") != -1 ) {
103 object res = oHandle->big_query("select k,v from mi_keyword_index");
104 object tagmod = get_module("tagging");
106 for ( int i = 0; i < res->num_rows(); i++ ) {
111 mixed erg = res->fetch_row();
112 if ( sscanf(erg[1], "%%%d", oid) != 1 )
114 if ( sscanf(erg[0], "\"%s\"", keyword) != 1 )
117 obj = find_object(oid);
120 if ( objectp(tagmod) )
121 tagmod->tag_object(obj, keyword);
123 catch(oHandle->big_query("drop table mi_keyword_index"));
125 MESSAGE("Converted " + res->num_rows() + " keywords");
127 mixed err = catch(oHandle->big_query("create fulltext index obkeywords on ob_class (obkeywords)"));
129 keywordUpdate = get_factory(CLASS_DOCUMENT)->execute((["name":"keywords"]));
130 keywordUpdate->set_content("Updated documents and acquire for OBJ_KEYWORDS!"+
131 (err!=0?sprintf("%O\n%O\n",err[0],err[1]):""));
132 keywordUpdate->move(dbupdates);
134 // userlookup index on login
135 object userLookupUpdate = dbupdates->get_object_byname("userLookup");
136 if ( !objectp(userLookupUpdate) ) {
137 catch(oHandle->big_query("create index loginlookup on i_userlookup (login)"));
138 catch(oHandle->big_query("create index emaillookup on i_userlookup (email)"));
139 catch(oHandle->big_query("create index firstnamelookup on i_userlookup (firstname)"));
140 catch(oHandle->big_query("create index lastnamelookup on i_userlookup (lastname)"));
142 userLookupUpdate = get_factory(CLASS_DOCUMENT)->execute((["name":"userLookup"]));
143 userLookupUpdate->set_content("Created indices on i_userlookup !");
144 userLookupUpdate->move(dbupdates);
147 object securityCache = dbupdates->get_object_byname("securityCache");
148 if ( !objectp(securityCache) ) {
149 catch(oHandle->big_query("create index securityklookup on i_security_cache \
151 catch(oHandle->big_query("create index securityvlookup on i_security_cache \
153 securityCache = get_factory(CLASS_DOCUMENT)->execute((["name":"securityCach\
155 securityCache->set_content("Created index on security cache !");
156 securityCache->move(dbupdates);
159 object obDataIndex = dbupdates->get_object_byname("obDataIndex");
160 if ( !objectp(obDataIndex) ) {
161 MESSAGE("Creating index on ob_data - could take a while depending on the size of your database!");
162 catch(oHandle->big_query("create index obdatalookup on ob_data (ob_data(40))"));
163 obDataIndex = get_factory(CLASS_DOCUMENT)->execute((["name":"obDataIndex"]));
164 obDataIndex->set_content("Created index on ob_data");
165 obDataIndex->move(dbupdates);
168 object binaryAttr = dbupdates->get_object_byname("Binary_Attributes");
169 if (!objectp(binaryAttr)) {
170 MESSAGE("Updating database (changing ob_data to use varchar(128) binary for ob_attr) - could take a while depending on the size of your database!");
171 mixed err=catch(oHandle->big_query("alter table ob_data modify ob_attr varchar(128) binary"));
173 MESSAGE("Error: %O\n%O", err[0], err[1]);
175 binaryAttr = get_factory(CLASS_DOCUMENT)->execute((["name":"Binary_Attributes",]));
176 binaryAttr->set_content("Collation on ob_data set to utf8_bin");
177 binaryAttr->move(dbupdates);
186 MESSAGE("creating table \"doc_data\" ");
187 oHandle->big_query("create table doc_data ("+
191 " primary key (doc_id, rec_order)"+
192 ") AVG_ROW_LENGTH=65535 MAX_ROWS=4294967296");
193 //FIXME: postgres does not support (and probably not even need)
194 //AVG_ROW_LENGTH and MAX_ROWS in this place
197 MESSAGE("creating table \"ob_class\" ");
198 oHandle->big_query("create table ob_class ("+
199 " ob_id int primary key, "+
200 " ob_class char(128) "+
203 MESSAGE("creating table \"ob_data\" ");
204 oHandle->big_query("create table ob_data ("+
206 " ob_ident char(15),"+
207 " ob_attr varchar(128) binary, "+
208 " ob_data mediumtext,"+
209 " unique(ob_id, ob_ident, ob_attr)"+
211 MESSAGE("creating table \"variables\" ");
212 oHandle->big_query("create table variables ("+
213 " var char(100) primary key, "+