00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "onphp.h"
00013 #include "onphp_util.h"
00014
00015 #include "ext/standard/php_string.h"
00016 #include "zend_globals.h"
00017 #include "zend_exceptions.h"
00018 #include "zend_interfaces.h"
00019
00020 #include "core/Base/Singleton.h"
00021 #include "core/DB/Dialect.h"
00022 #include "core/DB/ImaginaryDialect.h"
00023 #include "core/OSQL/DBValue.h"
00024 #include "core/OSQL/DialectString.h"
00025
00026 #if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2)
00027 #define onphp_implode(glue, words, copy) php_implode(glue, words, copy)
00028 #else
00029 #define onphp_implode(glue, words, copy) php_implode(glue, words, copy TSRMLS_CC)
00030 #endif
00031
00032 ONPHP_METHOD(ImaginaryDialect, me)
00033 {
00034 zval *instance, *class;
00035
00036 MAKE_STD_ZVAL(class);
00037 ZVAL_STRING(class, onphp_ce_ImaginaryDialect->name, 1);
00038
00039 zend_call_method_with_1_params(
00040 NULL,
00041 onphp_ce_Singleton,
00042 NULL,
00043 "getinstance",
00044 &instance,
00045 class
00046 );
00047
00048 ZVAL_FREE(class);
00049
00050 if (EG(exception)) {
00051 return;
00052 }
00053
00054 RETURN_ZVAL(instance, 1, 1);
00055 }
00056
00057 ONPHP_METHOD(ImaginaryDialect, preAutoincrement)
00058 {
00059 RETURN_NULL();
00060 }
00061
00062 ONPHP_METHOD(ImaginaryDialect, postAutoincrement)
00063 {
00064 RETURN_STRING("AUTOINCREMENT", 1);
00065 }
00066
00067 ONPHP_METHOD(ImaginaryDialect, hasTruncate)
00068 {
00069 RETURN_FALSE;
00070 }
00071
00072 ONPHP_METHOD(ImaginaryDialect, hasMultipleTruncate)
00073 {
00074 RETURN_FALSE;
00075 }
00076
00077 ONPHP_METHOD(ImaginaryDialect, quoteValue)
00078 {
00079 zval *value;
00080
00081 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE) {
00082 WRONG_PARAM_COUNT;
00083 }
00084
00085 RETURN_ZVAL(value, 1, 0);
00086 }
00087
00088 ONPHP_METHOD(ImaginaryDialect, quoteField)
00089 {
00090 zval *field;
00091
00092 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &field) == FAILURE) {
00093 WRONG_PARAM_COUNT;
00094 }
00095
00096 RETURN_ZVAL(field, 1, 0);
00097 }
00098
00099 ONPHP_METHOD(ImaginaryDialect, quoteTable)
00100 {
00101 zval *table;
00102
00103 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &table) == FAILURE) {
00104 WRONG_PARAM_COUNT;
00105 }
00106
00107 RETURN_ZVAL(table, 1, 0);
00108 }
00109
00110 ONPHP_METHOD(ImaginaryDialect, fieldToString)
00111 {
00112 zval *field, *out;
00113
00114 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &field) == FAILURE) {
00115 WRONG_PARAM_COUNT;
00116 }
00117
00118 if (
00119 Z_TYPE_P(field) == IS_OBJECT
00120 && instanceof_function(Z_OBJCE_P(field), onphp_ce_DialectString TSRMLS_CC)
00121 ) {
00122 zend_call_method_with_1_params(
00123 &field,
00124 Z_OBJCE_P(field),
00125 NULL,
00126 "todialectstring",
00127 &out,
00128 getThis()
00129 );
00130
00131 if (EG(exception)) {
00132 return;
00133 }
00134
00135 RETURN_ZVAL(out, 1, 1);
00136 } else {
00137 RETURN_ZVAL(field, 1, 0);
00138 }
00139 }
00140
00141 ONPHP_METHOD(ImaginaryDialect, valueToString)
00142 {
00143 zval *value;
00144
00145 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE) {
00146 WRONG_PARAM_COUNT;
00147 }
00148
00149 if (
00150 Z_TYPE_P(value) == IS_OBJECT
00151 && instanceof_function(Z_OBJCE_P(value), onphp_ce_DBValue TSRMLS_CC)
00152 ) {
00153 zval *out;
00154
00155 zend_call_method_with_1_params(
00156 &value,
00157 Z_OBJCE_P(value),
00158 NULL,
00159 "todialectstring",
00160 &out,
00161 value
00162 );
00163
00164 if (EG(exception)) {
00165 return;
00166 }
00167
00168 RETURN_ZVAL(out, 1, 1);
00169 }
00170
00171 RETURN_ZVAL(value, 1, 0);
00172 }
00173
00174 ONPHP_METHOD(ImaginaryDialect, fullTextSearch)
00175 {
00176 smart_str out = {0};
00177 zval *field, *words, *copy, *glue;
00178 long logic;
00179
00180 if (
00181 zend_parse_parameters(
00182 ZEND_NUM_ARGS() TSRMLS_CC,
00183 "zzl",
00184 &field,
00185 &words,
00186 &logic
00187 )
00188 == FAILURE
00189 ) {
00190 WRONG_PARAM_COUNT;
00191 }
00192
00193 MAKE_STD_ZVAL(glue);
00194 MAKE_STD_ZVAL(copy);
00195
00196 ZVAL_ZVAL(copy, words, 1, 0);
00197
00198 if (logic == 1) {
00199 ZVAL_STRING(glue, " & ", 1);
00200 } else {
00201 ZVAL_STRING(glue, " | ", 1);
00202 }
00203
00204 onphp_implode(glue, words, copy);
00205
00206 smart_str_appends(&out, "(\"");
00207
00208 if (
00209 Z_TYPE_P(field) == IS_OBJECT
00210 && instanceof_function(Z_OBJCE_P(field), onphp_ce_DialectString TSRMLS_CC)
00211 ) {
00212 zval *string;
00213
00214 zend_call_method_with_1_params(
00215 &getThis(),
00216 Z_OBJCE_P(getThis()),
00217 NULL,
00218 "fieldtostring",
00219 &string,
00220 field
00221 );
00222
00223 if (EG(exception)) {
00224 goto out;
00225 }
00226
00227 onphp_append_zval_to_smart_string(&out, string);
00228 zval_dtor(string);
00229 } else {
00230 onphp_append_zval_to_smart_string(&out, field);
00231 }
00232
00233 smart_str_appends(&out, "\" CONTAINS \"");
00234 smart_str_appends(&out, Z_STRVAL_P(copy));
00235 smart_str_appends(&out, "\")");
00236 smart_str_0(&out);
00237
00238 RETVAL_STRINGL(out.c, out.len, 0);
00239
00240 out:
00241 ZVAL_FREE(glue);
00242 ZVAL_FREE(copy);
00243 }
00244
00245 ONPHP_METHOD(ImaginaryDialect, fullTextRank)
00246 {
00247 smart_str out = {0};
00248 zval *field, *words, *copy, *glue;
00249 long logic;
00250
00251 if (
00252 zend_parse_parameters(
00253 ZEND_NUM_ARGS() TSRMLS_CC,
00254 "zzl",
00255 &field,
00256 &words,
00257 &logic
00258 )
00259 == FAILURE
00260 ) {
00261 WRONG_PARAM_COUNT;
00262 }
00263
00264 MAKE_STD_ZVAL(glue);
00265 MAKE_STD_ZVAL(copy);
00266
00267 ZVAL_ZVAL(copy, words, 1, 0);
00268
00269 if (logic == 1) {
00270 ZVAL_STRING(glue, " & ", 1);
00271 } else {
00272 ZVAL_STRING(glue, " | ", 1);
00273 }
00274
00275 onphp_implode(glue, words, copy);
00276
00277 smart_str_appends(&out, "(RANK BY \"");
00278
00279 if (
00280 Z_TYPE_P(field) == IS_OBJECT
00281 && instanceof_function(Z_OBJCE_P(field), onphp_ce_DialectString TSRMLS_CC)
00282 ) {
00283 zval *string;
00284
00285 zend_call_method_with_1_params(
00286 &getThis(),
00287 Z_OBJCE_P(getThis()),
00288 NULL,
00289 "fieldtostring",
00290 &string,
00291 field
00292 );
00293
00294 if (EG(exception)) {
00295 goto out;
00296 }
00297
00298 onphp_append_zval_to_smart_string(&out, string);
00299 zval_dtor(string);
00300 } else {
00301 onphp_append_zval_to_smart_string(&out, field);
00302 }
00303
00304 smart_str_appends(&out, "\" WHICH CONTAINS \"");
00305 smart_str_appends(&out, Z_STRVAL_P(copy));
00306 smart_str_appends(&out, "\")");
00307 smart_str_0(&out);
00308
00309 RETVAL_STRINGL(out.c, out.len, 0);
00310
00311 out:
00312 ZVAL_FREE(glue);
00313 ZVAL_FREE(copy);
00314 }
00315
00316 static ONPHP_ARGINFO_ONE;
00317 static ONPHP_ARGINFO_THREE;
00318 static ONPHP_ARGINFO_DBCOLUMN;
00319
00320 zend_function_entry onphp_funcs_ImaginaryDialect[] = {
00321 ONPHP_ME(ImaginaryDialect, me, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
00322 ONPHP_ME(ImaginaryDialect, preAutoincrement, arginfo_dbcolumn, ZEND_ACC_PUBLIC)
00323 ONPHP_ME(ImaginaryDialect, postAutoincrement, arginfo_dbcolumn, ZEND_ACC_PUBLIC)
00324 ONPHP_ME(ImaginaryDialect, hasTruncate, NULL, ZEND_ACC_PUBLIC)
00325 ONPHP_ME(ImaginaryDialect, hasMultipleTruncate, NULL, ZEND_ACC_PUBLIC)
00326 ONPHP_ME(ImaginaryDialect, quoteValue, arginfo_one, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
00327 ONPHP_ME(ImaginaryDialect, quoteField, arginfo_one, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
00328 ONPHP_ME(ImaginaryDialect, quoteTable, arginfo_one, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
00329 ONPHP_ME(ImaginaryDialect, fieldToString, arginfo_one, ZEND_ACC_PUBLIC)
00330 ONPHP_ME(ImaginaryDialect, valueToString, arginfo_one, ZEND_ACC_PUBLIC)
00331 ONPHP_ME(ImaginaryDialect, fullTextSearch, arginfo_three, ZEND_ACC_PUBLIC)
00332 ONPHP_ME(ImaginaryDialect, fullTextRank, arginfo_three, ZEND_ACC_PUBLIC)
00333 {NULL, NULL, NULL}
00334 };