1 package BSE::DB::Mysql;
8 our $VERSION = "1.014";
10 use vars qw($MAX_CONNECTION_AGE);
16 $MAX_CONNECTION_AGE = 1200;
20 # don't ever load the entire articles table
21 #Articles => 'select * from article',
23 'replace article values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
25 'insert article values (null, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
26 deleteArticle => 'delete from article where id = ?',
27 getArticleByPkey => 'select * from article where id = ?',
29 getArticleByLevel => 'select * from article where level = ?',
30 getArticleByParentid => 'select * from article where parentid = ?',
31 getArticleByLinkAlias => 'select * from article where linkAlias = ?',
32 'Articles.stepParents' => <<EOS,
33 select ar.* from article ar, other_parents op
34 where ar.id = op.parentId and op.childId = ?
35 order by op.childDisplayOrder desc
37 'Articles.visibleStepParents' => <<EOS,
38 select ar.* from article ar, other_parents op
39 where ar.id = op.parentId and op.childId = ?
40 and date_format(?, '%Y%m%d') between date_format(op.release, '%Y%m%d') and date_format(op.expire, '%Y%m%d')
42 order by op.childDisplayOrder desc
44 'Articles.stepKids' => <<EOS,
45 select ar.* from article ar, other_parents op
46 where op.childId = ar.id and op.parentId = ?
48 # originally "... and ? between op.release and op.expire"
49 # but since the first argument was a string, mysql treated the comparisons
50 # as string comparisons
51 'Articles.visibleStepKids' => <<EOS,
52 select ar.* from article ar, other_parents op
53 where op.childId = ar.id
55 and date_format(?, '%Y%m%d') between date_format(op.release, '%Y%m%d') and date_format(op.expire, '%Y%m%d') and listed <> 0
57 'Articles.ids'=>'select id from article',
58 articlePossibleStepparents => <<EOS,
59 select a.id, a.title from article a
60 where a.id not in (select parentId from other_parents where childId = ?)
63 articlePossibleStepchildren => <<EOS,
64 select a.id, a.title from article a
65 where a.id not in (select childId from other_parents where parentId = ?)
68 bse_MaxArticleDisplayOrder => <<EOS,
69 select max(displayOrder) as "displayOrder" from article
72 Images => 'select * from image',
74 'replace image values (?,?,?,?,?,?,?,?,?,?,?,?)',
75 addImage => 'insert image values(null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
76 deleteImage => 'delete from image where id = ?',
77 getImageByArticleId => 'select * from image where articleId = ? order by displayOrder',
78 getImageByPkey => 'select * from image where id = ?',
79 getImageByArticleIdAndName => <<SQL,
80 select * from image where articleId = ? and name = ?
83 dropIndex => 'delete from searchindex',
84 insertIndex => 'insert searchindex values(?, ?, ?, ?)',
85 searchIndex => 'select * from searchindex where id = ?',
86 searchIndexWC => 'select * from searchindex where id like ?',
88 Products=> 'select article.*, product.* from article, product where id = articleId',
89 addProduct => 'insert product values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
90 getProductByPkey => 'select article.*, product.* from article, product where id=? and articleId = id',
91 getProductByProduct_code => 'select article.*, product.* from article, product where product_code=? and articleId = id',
92 getProductByLinkAlias => 'select article.*, product.* from article, product where linkAlias=? and articleId = id',
93 replaceProduct => 'replace product values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
94 'Products.stepProducts' => <<EOS,
95 select ar.*, pr.* from article ar, product pr, other_parents op
96 where ar.id = pr.articleId and op.childId = ar.id and op.parentId = ?
98 'Products.visibleStep' => <<EOS,
99 select ar.*, pr.* from article ar, product pr, other_parents op
100 where ar.id = pr.articleId and op.childId = ar.id
101 and op.parentId = ? and ? between op.release and op.expire
104 'Products.subscriptionDependent' => <<SQL,
105 select ar.*, pr.* from article ar, product pr
106 where ar.id = pr.articleId
107 and (pr.subscription_id = ? or subscription_required = ?)
109 'Products.orderProducts' => <<SQL,
110 select ar.*, pr.* from article ar, product pr, order_item oi
111 where oi.orderId = ? and oi.productId = ar.id and ar.id = pr.articleId
113 deleteProduct => 'delete from product where articleId = ?',
114 'Products.userWishlist' => <<SQL,
115 select ar.*, pr.* from article ar, product pr, bse_wishlist wi
116 where wi.user_id = ? and wi.product_id = ar.id and ar.id = pr.articleId
117 order by wi.display_order desc
119 'Products.visible_children_of' => <<SQL,
120 select ar.*, pr.* from article ar, product pr
121 where ar.id = pr.articleId
124 and ? between ar.release and ar.expire
126 bse_userWishlistOrder => <<SQL,
127 select product_id, display_order
130 order by display_order desc
132 bse_userWishlistReorder => <<SQL,
134 set display_order = ?
135 where user_id = ? and product_id = ?
137 bse_addToWishlist => <<SQL,
138 insert into bse_wishlist(user_id, product_id, display_order)
141 bse_removeFromWishlist => <<SQL,
142 delete from bse_wishlist where user_id = ? and product_id = ?
145 Orders => 'select * from orders',
146 #getOrderByPkey => 'select * from orders where id = ?',
147 getOrderItemByOrderId => 'select * from order_item where orderId = ?',
148 #addOrder => 'insert orders values(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
149 #replaceOrder => 'replace orders values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
150 #addOrderItem => 'insert order_item values(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
151 #replaceOrderItem => 'replace order_item values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
152 #getOrderByUserId => 'select * from orders where userId = ?',
153 deleteOrdersItems => 'delete from order_item where orderId = ?',
155 getOrderItemByProductId => 'select * from order_item where productId = ?',
157 OtherParents => 'select * from other_parents',
158 getOtherParentByChildId => <<EOS,
159 select * from other_parents where childId = ? order by childDisplayOrder desc
161 getOtherParentByParentId => <<EOS,
162 select * from other_parents where parentId = ? order by parentDisplayOrder desc
164 getOtherParentByParentIdAndChildId =>
165 'select * from other_parents where parentId = ? and childId = ?',
166 addOtherParent=>'insert other_parents values(null,?,?,?,?,?,?)',
167 deleteOtherParent => 'delete from other_parents where id = ?',
168 replaceOtherParent=>'replace other_parents values(?,?,?,?,?,?,?)',
169 'OtherParents.anylinks' =>
170 'select * from other_parents where childId = ? or parentId = ?',
172 ArticleFiles => 'select * from article_files',
174 'insert into article_files values (null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
175 replaceArticleFile =>
176 'replace article_files values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
177 deleteArticleFile => 'delete from article_files where id = ?',
178 getArticleFileByArticleId =>
179 'select * from article_files where articleId = ? order by displayOrder desc',
180 getArticleFileByPkey => 'select * from article_files where id = ?',
182 "ArticleFiles.orderFiles" =><<SQL,
184 from article_files af, order_item oi
185 where af.articleId = oi.productId and oi.orderId = ?
186 order by oi.id, af.displayOrder desc
189 # getSiteUserByUserId =>
190 # 'select * from site_users where userId = ?',
191 # getSiteUserByPkey =>
192 # 'select * from site_users where id = ?',
193 # getSiteUserByAffiliate_name =>
194 # 'select * from site_users where affiliate_name = ?',
195 # addSiteUser => 'insert site_users values(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
196 # replaceSiteUser => 'replace site_users values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
197 'SiteUsers.removeSubscriptions'=>
198 'delete from subscribed_users where userId = ?',
199 'SiteUsers.removeSub'=>
200 'delete from subscribed_users where userId = ? and subId = ?',
201 'SiteUsers.subRecipients' => <<EOS,
202 select si.* from bse_siteusers si, subscribed_users su
203 where confirmed <> 0 and disabled = 0 and si.id = su.userId and su.subId = ?
205 SiteUsers => 'select * from bse_siteusers',
206 'SiteUsers.allSubscribers' => <<SQL,
208 from bse_siteusers su, orders od, order_item oi
209 where su.id = od.siteuser_id and od.id = oi.orderId
210 and oi.subscription_id <> -1
212 siteuserAllIds => 'select id from bse_siteusers',
213 getBSESiteuserImage => <<SQL,
214 select * from bse_siteuser_images
215 where siteuser_id = ? and image_id = ?
217 getBSESiteuserImages => <<SQL,
218 select * from bse_siteuser_images where siteuser_id = ?
220 addBSESiteuserImage => <<SQL,
221 insert bse_siteuser_images values(?,?,?,?,?,?,?,?)
223 replaceBSESiteuserImage => <<SQL,
224 replace bse_siteuser_images values(?,?,?,?,?,?,?,?)
226 deleteBSESiteuserImage=> <<SQL,
227 delete from bse_siteuser_images where siteuser_id = ? and image_id = ?
231 'select * from subscription_types',
232 addSubscriptionType=>
233 'insert subscription_types values(null,?,?,?,?,?,?,?,?,?,?,?,?)',
234 replaceSubscriptionType=>
235 'replace subscription_types values(?,?,?,?,?,?,?,?,?,?,?,?,?)',
236 getSubscriptionTypeByPkey =>
237 'select * from subscription_types where id = ? order by name',
238 deleteSubscriptionType =>
239 'delete from subscription_types where id = ?',
240 subRecipientCount => <<EOS,
241 select count(*) as "count" from bse_siteusers si, subscribed_users su
242 where confirmed <> 0 and disabled = 0 and si.id = su.userId and su.subId = ?
244 'SubscriptionTypes.userSubscribedTo' => <<'EOS',
245 select su.* from subscription_types su, subscribed_users us
246 where us.userId = ? and us.subId = su.id
250 'insert subscribed_users values(null,?,?)',
251 getSubscribedUserByUserId =>
252 'select * from subscribed_users where userId = ?',
254 # the following don't work with the row/table classes
256 'select id, title from article order by level, displayOrder desc',
258 getEmailBlackEntryByEmail =>
259 'select * from email_blacklist where email = ?',
260 addEmailBlackEntry =>
261 'insert email_blacklist values(null,?,?)',
264 'insert email_requests values(null,?,?,?,?)',
265 replaceEmailRequest =>
266 'replace email_requests values(?,?,?,?,?)',
267 deleteEmailRequest =>
268 'delete from email_requests where id = ?',
269 getEmailRequestByGenEmail =>
270 'select * from email_requests where genEmail = ?',
272 addAdminBase => 'insert into admin_base values(null, ?)',
273 replaceAdminBase => 'replace into admin_base values(?, ?)',
274 deleteAdminBase => 'delete from admin_base where id = ?',
275 getAdminBaseByPkey => 'select * from admin_base where id=?',
278 select bs.*, us.* from admin_base bs, admin_users us
279 where bs.id = us.base_id
282 getAdminUserByLogon => <<SQL,
283 select bs.*, us.* from admin_base bs, admin_users us
284 where bs.id = us.base_id and us.logon = ?
286 getAdminUserByPkey => <<SQL,
287 select bs.*, us.* from admin_base bs, admin_users us
288 where bs.id = us.base_id and bs.id = ?
290 addAdminUser => 'insert into admin_users values(?,?,?,?,?,?,?)',
291 replaceAdminUser => 'replace into admin_users values(?,?,?,?,?,?,?)',
292 deleteAdminUser => 'delete from admin_users where base_id = ?',
293 "AdminUsers.group_members" => <<SQL,
295 from admin_base bs, admin_users us, admin_membership am
296 where bs.id = us.base_id && am.group_id = ? and am.user_id = bs.id
299 adminUsersGroups => <<SQL,
301 from admin_base bs, admin_groups gr, admin_membership am
302 where bs.id = gr.base_id && am.user_id = ? and am.group_id = bs.id
305 userGroups => 'select * from admin_membership where user_id = ?',
306 deleteUserGroups => 'delete from admin_membership where user_id = ?',
308 AdminGroups => <<SQL,
310 from admin_base bs, admin_groups gr
311 where bs.id = gr.base_id
314 getAdminGroupByName => <<SQL,
315 select bs.*, gr.* from admin_base bs, admin_groups gr
316 where bs.id = gr.base_id and gr.name = ?
318 getAdminGroupByPkey => <<SQL,
319 select bs.*, gr.* from admin_base bs, admin_groups gr
320 where bs.id = gr.base_id and bs.id = ?
322 addAdminGroup => 'insert into admin_groups values(?,?,?,?,?)',
323 replaceAdminGroup => 'replace into admin_groups values(?,?,?,?,?)',
324 deleteAdminGroup => 'delete from admin_groups where base_id = ?',
325 groupUsers => 'select * from admin_membership where group_id = ?',
326 bseAdminGroupMember => <<SQL,
328 from admin_membership
332 'AdminGroups.userPermissionGroups' => <<SQL,
333 select bs.*, ag.* from admin_base bs, admin_groups ag, admin_membership am
334 where bs.id = ag.base_id
335 and ( (ag.base_id = am.group_id and am.user_id = ?)
336 or ag.name = 'everyone' )
339 addUserToGroup => 'insert into admin_membership values(?,?)',
340 delUserFromGroup => <<SQL,
341 delete from admin_membership where user_id = ? and group_id = ?
343 deleteGroupUsers => 'delete from admin_membership where group_id = ?',
345 articleObjectPerm => <<SQL,
346 select * from admin_perms where object_id = ? and admin_id = ?
348 addArticleObjectPerm => 'insert into admin_perms values(?,?,?)',
349 replaceArticleObjectPerm => 'replace into admin_perms values(?,?,?)',
353 where ap.admin_id = ?
357 from admin_perms ap, admin_membership am
358 where ap.admin_id = am.group_id and am.user_id = ?
360 commonPerms => <<SQL,
362 from admin_perms ap, admin_groups ag
363 where ap.admin_id = ag.base_id and ag.name = 'everyone'
365 Subscriptions => 'select * from bse_subscriptions',
366 addSubscription => 'insert bse_subscriptions values(null,?,?,?,?)',
367 replaceSubscription => 'replace bse_subscriptions values(?,?,?,?,?)',
368 deleteSubscription => <<SQL,
369 delete from bse_subscriptions where subscription_id = ?
371 getSubscriptionByPkey => <<SQL,
372 select * from bse_subscriptions where subscription_id = ?
374 getSubscriptionByText_id => <<SQL,
375 select * from bse_subscriptions where text_id = ?
377 subscriptionOrderItemCount => <<SQL,
378 select count(*) as "count" from order_item where subscription_id = ?
380 subscriptionOrderSummary => <<SQL,
381 select od.id, od.userId, od.orderDate, od.siteuser_id, od.billFirstName, od.billLastName, od.filled,
382 sum(oi.subscription_period * oi.units) as "subscription_period"
383 from orders od, order_item oi
384 where oi.subscription_id = ? and od.id = oi.orderId and od.complete <> 0
385 group by od.id, od.userId, od.orderDate, od.siteuser_id
386 order by od.orderDate desc
388 subscriptionUserSummary => <<SQL,
390 from bse_siteusers su, bse_user_subscribed us
391 where su.id = us.siteuser_id and us.subscription_id = ?
393 subscriptionProductCount => <<SQL,
394 select count(*) as "count" from product
395 where subscription_id = ? or subscription_required = ?
397 removeUserSubscribed => <<SQL,
398 delete from bse_user_subscribed where subscription_id = ? and siteuser_id = ?
400 addUserSubscribed => <<SQL,
401 insert bse_user_subscribed values (?,?,?,?,?)
403 subscriptionUserBought => <<SQL,
405 oi.subscription_period * oi.units as "subscription_period",
407 od.id as "order_id", oi.id as "item_id", oi.productId as "product_id"
408 from orders od, order_item oi
409 where oi.subscription_id = ? and od.id = oi.orderId and od.siteuser_id = ?
412 userSubscribedEntry => <<SQL,
413 select * from bse_user_subscribed
414 where siteuser_id = ? and subscription_id = ?
416 siteuserSubscriptions => <<SQL,
417 select su.*, us.started_at, us.ends_at, us.max_lapsed
418 from bse_subscriptions su, bse_user_subscribed us
419 where us.siteuser_id = ? and us.subscription_id = su.subscription_id
420 and us.ends_at >= curdate()
423 addLocation => <<SQL,
424 insert bse_locations values(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
426 replaceLocation => <<SQL,
427 replace bse_locations values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
429 getLocationByPkey => 'select * from bse_locations where id = ?',
430 deleteLocation => 'delete from bse_locations where id = ?',
431 Locations => 'select * from bse_locations order by description',
434 select ar.*, pr.*, se.*
435 from article ar, product pr, bse_seminars se
436 where ar.id = pr.articleId and ar.id = se.seminar_id
438 addSeminar => 'insert bse_seminars values(?,?)',
439 replaceSeminar => 'replace bse_seminars values(?,?)',
440 deleteSeminar => 'delete from bse_seminars where seminar_id = ?',
441 getSeminarByPkey => <<SQL,
442 select ar.*, pr.*, se.*
443 from article ar, product pr, bse_seminars se
444 where id = ? and ar.id = pr.articleId and ar.id = se.seminar_id
446 getSeminarByProduct_code => <<SQL,
447 select ar.*, pr.*, se.*
448 from article ar, product pr, bse_seminars se
449 where product_code = ? and ar.id = pr.articleId and ar.id = se.seminar_id
451 'Locations.seminarFuture' => <<SQL,
453 from bse_locations lo, bse_seminar_sessions ss
454 where ss.seminar_id = ? and ss.when_at > ?
455 and ss.location_id = lo.id
456 order by lo.description
458 'Locations.session_id' => <<SQL,
460 from bse_locations lo, bse_seminar_sessions ss
461 where lo.id = ss.location_id and ss.id = ?
464 seminarSessionInfo => <<SQL,
465 select se.*, lo.description
466 from bse_seminar_sessions se, bse_locations lo
467 where se.seminar_id = ? and se.location_id = lo.id
468 order by when_at desc
470 seminarFutureSessionInfo => <<SQL,
471 select se.*, lo.description, lo.room, lo.street1, lo.street2, lo.suburb,
472 lo.state, lo.country, lo.postcode, lo.public_notes
473 from bse_seminar_sessions se, bse_locations lo
474 where se.seminar_id = ? and se.when_at > ? and se.location_id = lo.id
475 order by when_at desc
477 addSeminarSession => 'insert bse_seminar_sessions values(null,?,?,?,?)',
478 replaceSeminarSession => 'replace bse_seminar_sessions values(?,?,?,?,?)',
479 deleteSeminarSession => 'delete from bse_seminar_sessions where id = ?',
480 getSeminarSessionByPkey => 'select * from bse_seminar_sessions where id = ?',
481 getSeminarSessionByLocation_idAndWhen_at => <<SQL,
482 select * from bse_seminar_sessions
483 where location_id = ? and when_at = ?
485 getSeminarSessionBySeminar_id => <<SQL,
486 select * from bse_seminar_sessions
489 'SeminarSessions.futureSessions' => <<SQL,
490 select * from bse_seminar_sessions
491 where seminar_id = ? and when_at >= ?
493 'SeminarSessions.futureSeminarLocation' => <<SQL,
495 from bse_seminar_sessions
496 where seminar_id = ? and location_id = ? and when_at > ?
498 'SiteUsers.sessionBookings' => <<SQL,
499 select su.* from bse_siteusers su, bse_seminar_bookings sb
500 where sb.session_id = ? and su.id = sb.siteuser_id
502 cancelSeminarSessionBookings => <<SQL,
503 delete from bse_seminar_bookings where session_id = ?
505 conflictSeminarSessions => <<SQL,
506 select bo1.siteuser_id
507 from bse_seminar_bookings bo1, bse_seminar_bookings bo2
508 where bo1.session_id = ? and bo2.session_id = ?
509 and bo1.siteuser_id = bo2.siteuser_id
511 seminarSessionBookedIds => <<SQL,
512 select * from bse_seminar_bookings where session_id = ?
514 addSeminarBooking => <<SQL,
515 insert bse_seminar_bookings values(null,?,?,?,?,?,?)
517 seminarSessionRollCallEntries => <<SQL,
518 select bo.roll_present, su.id, su.userId, su.name1, su.name2, su.email,
520 from bse_seminar_bookings bo, bse_siteusers su
521 where bo.session_id = ? and bo.siteuser_id = su.id
523 updateSessionRollPresent => <<SQL,
524 update bse_seminar_bookings
526 where session_id = ? and siteuser_id = ?
528 userSeminarSessionBookings => <<SQL,
530 from bse_seminar_bookings sb, bse_seminar_sessions ss
531 where ss.seminar_id = ? and ss.id = sb.session_id and siteuser_id = ?
533 SiteUserGroups => 'select * from bse_siteuser_groups',
534 addSiteUserGroup => 'insert bse_siteuser_groups values(null,?)',
535 replaceSiteUserGroup => 'replace bse_siteuser_groups values(?,?)',
536 deleteSiteUserGroup => 'delete from bse_siteuser_groups where id = ?',
537 getSiteUserGroupByPkey => 'select * from bse_siteuser_groups where id = ?',
538 getSiteUserGroupByName => 'select * from bse_siteuser_groups where name = ?',
539 siteuserGroupMemberIds => <<SQL,
540 select siteuser_id as "id"
541 from bse_siteuser_membership
544 siteuserGroupAddMember => <<SQL,
545 insert bse_siteuser_membership values(?,?)
547 siteuserGroupDeleteMember => <<SQL,
548 delete from bse_siteuser_membership where group_id = ? and siteuser_id = ?
550 siteuserGroupDeleteAllMembers => <<SQL,
551 delete from bse_siteuser_membership where group_id = ?
553 siteuserMemberOfGroup => <<SQL,
554 select * from bse_siteuser_membership
555 where siteuser_id = ? and group_id = ?
557 siteuserGroupsForUser => <<SQL,
558 select group_id as "id" from bse_siteuser_membership where siteuser_id = ?
561 articleAccessibleToGroup => <<SQL,
562 select * from bse_article_groups
563 where article_id = ? and group_id = ?
565 siteuserGroupsForArticle => <<SQL,
566 select group_id as "id" from bse_article_groups
569 articleAddSiteUserGroup => <<SQL,
570 insert bse_article_groups values(?,?)
572 articleDeleteSiteUserGroup => <<SQL,
573 delete from bse_article_groups
574 where article_id = ? and group_id = ?
576 siteuserGroupDeleteAllPermissions => <<SQL,
577 delete from bse_article_groups where group_id = ?
581 # called when we start working on a new request, mysql seems to have
582 # problems with old connections sometimes, or so it seems, so
583 # disconnect occasionally (only matters for fastcgi, mod_perl)
588 unless ($self->{dbh}->ping) {
589 print STDERR "Database connection lost - reconnecting\n";
590 $self->{dbh} = $class->connect;
591 $self->{birth} = time();
597 my ($class, $dbname) = @_;
599 my $dsn = $class->dsn($dbname);
600 my $un = $self->dbuser($dbname);
601 my $pass = $self->dbpassword($dbname);
602 my $dbopts = $self->dbopts($dbname);
603 my $dbh = DBI->connect( $dsn, $un, $pass, $dbopts)
604 or die "Cannot connect to database: $DBI::errstr";
606 # this might fail, but I don't care
607 $dbh->do("set session sql_mode='ansi_quotes'");
614 my ($class, $cfg) = @_;
616 warn "Incorrect number of parameters passed to BSE::DB::Mysql::single\n" unless @_ == 2;
618 unless ( defined $self ) {
626 $self->{dbh} = $self->connect;
634 $self->{dbh}{InactiveDestroy} = 1;
636 $self->{dbh} = $self->connect;
640 my $get_sql_by_name = 'select sql_statement from sql_statements where name=?';
645 my ($self, $name) = @_;
647 $name =~ s/BSE.*:://;
649 my $sql = $statements{$name};
651 if (exists $sql_cache{$name}) {
652 return $sql_cache{$name};
656 my @row = $self->{dbh}->selectrow_array($get_sql_by_name, {}, $name);
659 #print STDERR "Found SQL '$sql'\n";
662 #print STDERR "SQL statment $name not found in sql_statements table\n";
665 $sql_cache{$name} = $sql;
672 my ($self, $name) = @_;
674 my $sql = $self->stmt_sql($name)
675 or confess "Statement named '$name' not found";
676 my $sth = $self->{dbh}->prepare($sql)
677 or croak "Cannot prepare $name statment: ",$self->{dbh}->errstr;
683 my ($self, $name) = @_;
685 my $sql = $self->stmt_sql($name)
687 my $sth = $self->{dbh}->prepare($sql)
688 or croak "Cannot prepare $name statment: ",$self->{dbh}->errstr;
694 my ($self, $sth) = @_;
696 my $id = $sth->{"mysql_insertid"};
704 my $opts = $class->SUPER::dbopts();
707 && lc(BSE::Cfg->charset) eq "utf-8") {
708 $opts->{mysql_enable_utf8} = 1;
718 # this is wierd - we only need to reset this on 5.6.x (for x == 0 so
720 # Works fine without the reset for 5.005_03
722 $self->{dbh}->disconnect;