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: 27: 28: 29: 30: 31: 32: 33: 34:
35: public function buildJoinQuery($destinationTable, $destinationClass, $destinationPrimaryKey, $sourceClass, $primaryKey) {
36:
37: $field = "$destinationClass.$destinationPrimaryKey";
38: $tables = "";
39: $join = "LEFT JOIN $destinationTable AS $destinationClass ON " . cSecurity::toString($sourceClass . "." . $primaryKey) . " = " . cSecurity::toString($destinationClass . "." . $primaryKey);
40: $where = "";
41:
42: return array(
43: "field" => $field,
44: "table" => $tables,
45: "join" => $join,
46: "where" => $where
47: );
48: }
49:
50: 51: 52: 53: 54: 55: 56:
57: public function buildOperator($sField, $sOperator, $sRestriction) {
58: $sOperator = cString::toLowerCase($sOperator);
59:
60: $sWhereStatement = "";
61:
62: switch ($sOperator) {
63: case "matchbool":
64: $sqlStatement = "MATCH (%s) AGAINST ('%s' IN BOOLEAN MODE)";
65: $sWhereStatement = sprintf($sqlStatement, $sField, $this->_oItemClassInstance->_inFilter($sRestriction));
66: break;
67: case "match":
68: $sqlStatement = "MATCH (%s) AGAINST ('%s')";
69: $sWhereStatement = sprintf($sqlStatement, $sField, $this->_oItemClassInstance->_inFilter($sRestriction));
70: break;
71: case "like":
72: $sqlStatement = "%s LIKE '%%%s%%'";
73: $sWhereStatement = sprintf($sqlStatement, cSecurity::toString($sField), $this->_oItemClassInstance->_inFilter($sRestriction));
74: break;
75: case "likeleft":
76: $sqlStatement = "%s LIKE '%s%%'";
77: $sWhereStatement = sprintf($sqlStatement, cSecurity::toString($sField), $this->_oItemClassInstance->_inFilter($sRestriction));
78: break;
79: case "likeright":
80: $sqlStatement = "%s LIKE '%%%s'";
81: $sWhereStatement = sprintf($sqlStatement, cSecurity::toString($sField), $this->_oItemClassInstance->_inFilter($sRestriction));
82: break;
83: case "notlike":
84: $sqlStatement = "%s NOT LIKE '%%%s%%'";
85: $sWhereStatement = sprintf($sqlStatement, cSecurity::toString($sField), $this->_oItemClassInstance->_inFilter($sRestriction));
86: break;
87: case "notlikeleft":
88: $sqlStatement = "%s NOT LIKE '%s%%'";
89: $sWhereStatement = sprintf($sqlStatement, cSecurity::toString($sField), $this->_oItemClassInstance->_inFilter($sRestriction));
90: break;
91: case "notlikeright":
92: $sqlStatement = "%s NOT LIKE '%%%s'";
93: $sWhereStatement = sprintf($sqlStatement, cSecurity::toString($sField), $this->_oItemClassInstance->_inFilter($sRestriction));
94: break;
95: case "fulltext":
96:
97: break;
98: case "in":
99: if (is_array($sRestriction)) {
100: $items = array();
101:
102: foreach ($sRestriction as $key => $sRestrictionItem) {
103: $items[] = "'" . $this->_oItemClassInstance->_inFilter($sRestrictionItem) . "'";
104: }
105:
106: $sRestriction = implode(", ", $items);
107: } else {
108: $sRestriction = "'" . $sRestriction . "'";
109: }
110:
111: $sWhereStatement = implode(" ", array(
112: $sField,
113: "IN (",
114: $sRestriction,
115: ")"
116: ));
117: break;
118: default:
119: $sRestriction = "'" . $this->_oItemClassInstance->_inFilter($sRestriction) . "'";
120:
121: $sWhereStatement = implode(" ", array(
122: $sField,
123: $sOperator,
124: $sRestriction
125: ));
126: }
127:
128: return $sWhereStatement;
129: }
130: }
131: