1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23:
24: class cGenericDbDriverMysql extends cGenericDbDriver {
25:
26: public function buildJoinQuery($destinationTable, $destinationClass, $destinationPrimaryKey, $sourceClass, $primaryKey) {
27:
28: $field = "$destinationClass.$destinationPrimaryKey";
29: $tables = "";
30: $join = "LEFT JOIN $destinationTable AS $destinationClass ON " . cSecurity::toString($sourceClass . "." . $primaryKey) . " = " . cSecurity::toString($destinationClass . "." . $primaryKey);
31: $where = "";
32:
33: return array(
34: "field" => $field,
35: "table" => $tables,
36: "join" => $join,
37: "where" => $where
38: );
39: }
40:
41: public function buildOperator($sField, $sOperator, $sRestriction) {
42: $sOperator = strtolower($sOperator);
43:
44: $sWhereStatement = "";
45:
46: switch ($sOperator) {
47: case "matchbool":
48: $sqlStatement = "MATCH (%s) AGAINST ('%s' IN BOOLEAN MODE)";
49: $sWhereStatement = sprintf($sqlStatement, $sField, $this->_oItemClassInstance->_inFilter($sRestriction));
50: break;
51: case "match":
52: $sqlStatement = "MATCH (%s) AGAINST ('%s')";
53: $sWhereStatement = sprintf($sqlStatement, $sField, $this->_oItemClassInstance->_inFilter($sRestriction));
54: break;
55: case "like":
56: $sqlStatement = "%s LIKE '%%%s%%'";
57: $sWhereStatement = sprintf($sqlStatement, cSecurity::toString($sField), $this->_oItemClassInstance->_inFilter($sRestriction));
58: break;
59: case "likeleft":
60: $sqlStatement = "%s LIKE '%s%%'";
61: $sWhereStatement = sprintf($sqlStatement, cSecurity::toString($sField), $this->_oItemClassInstance->_inFilter($sRestriction));
62: break;
63: case "likeright":
64: $sqlStatement = "%s LIKE '%%%s'";
65: $sWhereStatement = sprintf($sqlStatement, cSecurity::toString($sField), $this->_oItemClassInstance->_inFilter($sRestriction));
66: break;
67: case "notlike":
68: $sqlStatement = "%s NOT LIKE '%%%s%%'";
69: $sWhereStatement = sprintf($sqlStatement, cSecurity::toString($sField), $this->_oItemClassInstance->_inFilter($sRestriction));
70: break;
71: case "notlikeleft":
72: $sqlStatement = "%s NOT LIKE '%s%%'";
73: $sWhereStatement = sprintf($sqlStatement, cSecurity::toString($sField), $this->_oItemClassInstance->_inFilter($sRestriction));
74: break;
75: case "notlikeright":
76: $sqlStatement = "%s NOT LIKE '%%%s'";
77: $sWhereStatement = sprintf($sqlStatement, cSecurity::toString($sField), $this->_oItemClassInstance->_inFilter($sRestriction));
78: break;
79: case "fulltext":
80:
81: break;
82: case "in":
83: if (is_array($sRestriction)) {
84: $items = array();
85:
86: foreach ($sRestriction as $key => $sRestrictionItem) {
87: $items[] = "'" . $this->_oItemClassInstance->_inFilter($sRestrictionItem) . "'";
88: }
89:
90: $sRestriction = implode(", ", $items);
91: } else {
92: $sRestriction = "'" . $sRestriction . "'";
93: }
94:
95: $sWhereStatement = implode(" ", array(
96: $sField,
97: "IN (",
98: $sRestriction,
99: ")"
100: ));
101: break;
102: default:
103: $sRestriction = "'" . $this->_oItemClassInstance->_inFilter($sRestriction) . "'";
104:
105: $sWhereStatement = implode(" ", array(
106: $sField,
107: $sOperator,
108: $sRestriction
109: ));
110: }
111:
112: return $sWhereStatement;
113: }
114:
115: }
116: