1 28 29 package com.caucho.amber.query; 30 31 import java.sql.PreparedStatement; 32 import java.sql.SQLException; 33 34 import com.caucho.util.CharBuffer; 35 36 import com.caucho.amber.type.Type; 37 38 41 class ArgExpr extends AbstractAmberExpr { 42 private QueryParser _parser; 43 44 private int _index; 46 47 private int _sqlIndex; 48 49 50 55 ArgExpr(QueryParser parser, int index) 56 { 57 _parser = parser; 58 59 _index = index; 60 } 61 62 65 int getIndex() 66 { 67 return _index; 68 } 69 70 73 public AmberExpr bindSelect(QueryParser parser) 74 { 75 parser.addArg(this); 76 77 return this; 78 } 79 80 83 public void generateWhere(CharBuffer cb) 84 { 85 _sqlIndex = _parser.generateSQLArg(); 86 87 cb.append("?"); 88 } 89 90 93 public void setParameter(PreparedStatement pstmt, int i, 94 Type []argTypes, Object []argValues) 95 throws SQLException 96 { 97 if (argTypes[_index - 1] != null) 98 argTypes[_index - 1].setParameter(pstmt, _sqlIndex + 1, 99 argValues[_index - 1]); 100 else 101 pstmt.setString(_sqlIndex + 1, null); 102 } 103 104 public String toString() 105 { 106 return "?" + _index; 107 } 108 } 109 | Popular Tags |