1 29 30 package com.caucho.quercus.lib.db; 31 32 import com.caucho.quercus.QuercusModuleException; 33 import com.caucho.quercus.UnimplementedException; 34 import com.caucho.quercus.annotation.Reference; 35 import com.caucho.quercus.annotation.ReturnNullAsFalse; 36 import com.caucho.quercus.env.BooleanValue; 37 import com.caucho.quercus.env.Env; 38 import com.caucho.quercus.env.LongValue; 39 import com.caucho.quercus.env.NullValue; 40 import com.caucho.quercus.env.Value; 41 import com.caucho.util.L10N; 42 43 import java.util.logging.Level ; 44 import java.util.logging.Logger ; 45 46 47 50 public class MysqliStatement extends JdbcStatementResource { 51 private static final Logger log = Logger.getLogger(MysqliStatement.class.getName()); 52 private static final L10N L = new L10N(MysqliStatement.class); 53 54 59 MysqliStatement(Mysqli conn) 60 { 61 super(conn); 62 } 63 64 75 public int affected_rows(Env env) 76 { 77 try { 78 return validateConnection().getAffectedRows(); 79 } catch (Exception e) { 80 log.log(Level.FINE, e.toString(), e); 81 return -1; 82 } 83 } 84 85 93 public boolean bind_param(Env env, 94 String types, 95 @Reference Value[] params) 96 { 97 try { 98 return bindParams(env, types, params); 99 } catch (Exception e) { 100 log.log(Level.FINE, e.toString(), e); 101 return false; 102 } 103 } 104 105 112 public boolean bind_result(Env env, 113 @Reference Value[] outParams) 114 { 115 try { 116 return bindResults(env, outParams); 117 } catch (Exception e) { 118 log.log(Level.FINE, e.toString(), e); 119 return false; 120 } 121 } 122 123 129 public boolean close(Env env) 130 { 131 try { 132 super.close(); 133 return true; 134 } catch (Exception e) { 135 log.log(Level.FINE, e.toString(), e); 136 return false; 137 } 138 } 139 140 147 public Value data_seek(Env env, 148 int offset) 149 { 150 try { 151 152 if (dataSeek(offset)) 153 return NullValue.NULL; 154 155 } catch (Exception e) { 156 log.log(Level.FINE, e.toString(), e); 157 } 158 159 return BooleanValue.FALSE; 160 } 161 162 168 public int errno(Env env) 169 { 170 try { 171 return errorCode(); 172 } catch (Exception e) { 173 log.log(Level.FINE, e.toString(), e); 174 return -1; 175 } 176 } 177 178 184 @ReturnNullAsFalse 185 public String error(Env env) 186 { 187 try { 188 return errorMessage(); 189 } catch (Exception e) { 190 log.log(Level.FINE, e.toString(), e); 191 return null; 192 } 193 } 194 195 201 public boolean execute(Env env) 202 { 203 try { 204 return super.execute(env); 205 } catch (Exception e) { 206 log.log(Level.FINE, e.toString(), e); 207 return false; 208 } 209 } 210 211 217 public Value fetch(Env env) 218 { 219 try { 220 return super.fetch(env); 221 } catch (Exception e) { 222 log.log(Level.FINE, e.toString(), e); 223 return BooleanValue.FALSE; 224 } 225 } 226 227 232 public void free_result(Env env) 233 { 234 try { 235 freeResult(); 236 } catch (Exception e) { 237 log.log(Level.FINE, e.toString(), e); 238 } 239 } 240 241 247 public Value num_rows(Env env) 248 { 249 try { 250 if (getResultSet() != null) 251 return LongValue.create(JdbcResultResource.getNumRows(getResultSet())); 252 else 253 return BooleanValue.FALSE; 254 } catch (Exception e) { 255 log.log(Level.FINE, e.toString(), e); 256 return BooleanValue.FALSE; 257 } 258 } 259 260 266 public int param_count(Env env) 267 { 268 try { 269 return paramCount(); 270 } catch (Exception e) { 271 log.log(Level.FINE, e.toString(), e); 272 return -1; 273 } 274 } 275 276 283 public boolean prepare(Env env, 284 String query) 285 { 286 try { 287 return super.prepare(query); 288 } catch (Exception e) { 289 log.log(Level.FINE, e.toString(), e); 290 return false; 291 } 292 } 293 294 300 public boolean reset(Env env) 301 { 302 return true; 303 } 304 305 348 @ReturnNullAsFalse 349 public MysqliResult result_metadata(Env env) 350 { 351 try { 352 353 if (getResultSet() != null) { 354 return new MysqliResult(getMetaData(), 355 (Mysqli) validateConnection()); 356 } else 357 return null; 358 359 } catch (Exception e) { 360 throw new QuercusModuleException(e); 361 } 362 } 363 364 372 public boolean send_long_data(Env env, 373 int paramNumber, 374 String data) 375 { 376 throw new UnimplementedException("mysqli_stmt_send_long_data"); 377 } 378 379 385 @ReturnNullAsFalse 386 public String sqlstate(Env env) 387 { 388 try { 389 return "HY" + errno(env); 390 } catch (Exception e) { 391 log.log(Level.FINE, e.toString(), e); 392 return null; 393 } 394 } 395 396 402 public boolean store_result(Env env) 403 { 404 return true; 405 } 406 } 407 | Popular Tags |