1 9 package com.ziclix.python.sql.handler; 10 11 import com.ziclix.python.sql.DataHandler; 12 import org.python.core.PyFile; 13 import org.python.core.PyObject; 14 15 import java.io.BufferedInputStream ; 16 import java.io.ByteArrayInputStream ; 17 import java.io.InputStream ; 18 import java.sql.PreparedStatement ; 19 import java.sql.SQLException ; 20 import java.sql.Types ; 21 22 29 public class MySQLDataHandler extends RowIdHandler { 30 31 36 public MySQLDataHandler(DataHandler datahandler) { 37 super(datahandler); 38 } 39 40 protected String getRowIdMethodName() { 41 return "getLastInsertID"; 42 } 43 44 47 public void setJDBCObject(PreparedStatement stmt, int index, PyObject object, int type) throws SQLException { 48 49 if (DataHandler.checkNull(stmt, index, object, type)) { 50 return; 51 } 52 53 switch (type) { 54 55 case Types.LONGVARCHAR: 56 String varchar; 57 if (object instanceof PyFile) { 58 varchar = ((PyFile) object).read(); 59 } else { 60 varchar = (String ) object.__tojava__(String .class); 61 } 62 InputStream stream = new ByteArrayInputStream (varchar.getBytes()); 63 64 stream = new BufferedInputStream (stream); 65 66 stmt.setAsciiStream(index, stream, varchar.length()); 67 break; 68 69 default : 70 super.setJDBCObject(stmt, index, object, type); 71 break; 72 } 73 } 74 } 75 | Popular Tags |