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