File: mysql.pm

package info (click to toggle)
movabletype-opensource 5.1.4%2Bdfsg-4%2Bdeb7u3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 32,996 kB
  • sloc: perl: 197,285; php: 62,405; sh: 166; xml: 117; makefile: 83; sql: 32
file content (61 lines) | stat: -rw-r--r-- 1,692 bytes parent folder | download
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
# Movable Type (r) Open Source (C) 2001-2012 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id$

package MT::ObjectDriver::SQL::mysql;

use strict;
use warnings;
use base qw( MT::ObjectDriver::SQL );

sub new {
    my $class = shift;
    my %param = @_;
    my $sql   = $class->SUPER::new(%param);
    if ( my $cols = $sql->binary ) {
        foreach my $col ( keys %$cols ) {
            my $t = $sql->transform->{$col};
            if ( $t && ( $t =~ /\)$/ ) ) {
                $sql->transform->{$col} = 'binary ' . $t;
            }
            elsif ($t) {
                $sql->transform->{$col} = "$t($col)";
            }
            else {
                $sql->transform->{$col} = "binary($col)";
            }
            $sql->transform->{ $col . '__NOBINARY' } = $col;
        }
    }
    return $sql;
}

sub _mk_term {
    my $stmt = shift;
    my ( $col, $val ) = @_;

    if ( my $transform = $stmt->transform ) {
        my ( $table_name, $col_name ) = $col =~ m{ \A mt_(\w+)\.(\w+) }xms;
        if ($table_name) {
            my $key = join( '_', $table_name, $col_name );
            if ( $transform->{ $key . '__NOBINARY' } ) {
                $stmt->add_where( $col . '__NOBINARY', $val );
            }
        }
    }
    return $stmt->SUPER::_mk_term(@_);
}

sub add_freetext_where {
    my $stmt = shift;
    my ( $columns, $search_string ) = @_;
    my $col = 'MATCH(' . join( ', ', @$columns ) . ')';
    my $term = "($col AGAINST(? IN BOOLEAN MODE))";
    push @{ $stmt->{where} }, "($term)";
    push @{ $stmt->{bind} },  $search_string;
    $stmt->where_values->{$col} = $search_string;
}

1;