1 11 12 package com.nilostep.xlsql.sql.mckoi; 13 14 import com.nilostep.xlsql.sql.xlSql; 15 import com.nilostep.xlsql.database.*; 16 import com.nilostep.xlsql.sql.*; 17 18 import java.sql.*; 19 import java.util.regex.*; 20 21 26 public class xlMcKoi extends xlSql { 27 29 private final int SET_SCHEMA = 7; 30 private String context; 31 32 38 public xlMcKoi(com.nilostep.xlsql.database.xlDatabase xlsqldb, 39 String mckoischema) { 40 super(xlsqldb); 41 42 if (mckoischema == null) { 43 throw new NullPointerException ("xlSQL: mckoi schema null"); 44 } 45 46 context = mckoischema; 47 } 48 49 51 protected int getCmd(String sql) { 52 return 0; 53 } 54 55 protected String [] getVars(int cmd, String sql) { 56 String [] v = new String [4]; 57 String tmp = ""; 58 59 switch (cmd) { 60 case INSERT: 61 tmp = sql.replaceAll( 62 "\\s*[Ii][Nn][Ss][Ee][Rr][Tt].*[Ii][Nn][Tt][Oo]\\s*", 63 ""); 64 tmp = tmp.substring(0, tmp.indexOf("(")); 65 tmp = tmp.replaceAll("\\s*[Vv][Aa][Ll][Uu][Ee][Ss].*", ""); 66 break; 67 68 case UPDATE: 69 tmp = sql.replaceAll("\\s*[Uu][Pp][Dd][Aa][Tt][Ee]\\s*", ""); 70 tmp = tmp.replaceAll("\\s*[Ss][Ee][Tt].*", ""); 71 break; 72 73 case DELETE: 74 tmp = sql.replaceAll( 75 "\\s*[Dd][Ee][Ll][Ee][Tt][Ee].*[Ff][Rr][Oo][Mm]\\s*", 76 ""); 77 tmp = tmp.replaceAll("\\s*[Ww][Hh][Ee][Rr][Ee].*", ""); 78 break; 79 80 case CREATE_TABLE: 81 tmp = sql.replaceAll("\\s*[Cc][Rr][Ee][Aa][Tt][Ee]\\s*", ""); 82 tmp = tmp.substring(6); 83 tmp = tmp.replaceAll("\\s*[(].*", ""); 84 break; 85 86 case DROP_TABLE: 87 tmp = sql.replaceAll("\\s*[Dd][Rr][Oo][Pp]\\s*", ""); 88 tmp = tmp.substring(6); 89 tmp = tmp.replaceAll("\\s*[Ii][Ff].*[Ee][Xx][Ii][Ss][Tt][Ss]\\s*", ""); 90 break; 91 92 case RENAME_TABLE: 93 tmp = sql.replaceAll("\\s*[Aa][Ll][Tt][Ee][Rr]\\s*", ""); 94 tmp = tmp.trim(); 95 tmp = tmp.substring(6); 96 String [] s = tmp.split("[Rr][Ee][Nn][Aa][Mm][Ee].*[Tt][Oo]"); 97 if (s.length < 2) { 98 s = tmp.split("[Rr][Ee][Nn][Aa][Mm][Ee]"); 99 } 100 String tmp_old = s[0].trim(); 101 tmp_old = tmp_old.replaceAll("[\"]", ""); 102 tmp = s[1].trim(); 103 tmp = tmp.replaceAll("[\"]", ""); 104 if (tmp_old.indexOf(DOT) == -1) { 105 v[2] = context; 106 v[3] = tmp_old; 107 } else { 108 v[2] = tmp_old.substring(0, tmp_old.indexOf(DOT)); 109 v[3] = tmp_old.substring(1 + tmp_old.indexOf(DOT), 110 tmp_old.length()); 111 } 112 break; 113 114 case ALTER_TABLE: 115 tmp = sql.replaceAll("\\s*[Aa][Ll][Tt][Ee][Rr]\\s*", ""); 116 tmp = tmp.substring(5); 117 tmp = tmp.substring(0, tmp.indexOf(" ")); 118 break; 119 120 case SET_SCHEMA: 121 tmp = sql.replaceAll("\\s*[Ss][Ee][Tt]\\s*", ""); 122 tmp = tmp.substring(7); 123 tmp = tmp.replaceAll("[;]", ""); 124 tmp = tmp.trim(); 125 context = tmp; 126 127 default: 128 break; 129 } 130 131 tmp = tmp.trim(); 132 tmp = tmp.replaceAll("[;]", ""); 133 tmp = tmp.replaceAll("[\"]", ""); 134 if (tmp.indexOf(DOT) == -1) { 135 v[0] = context; 136 v[1] = tmp; 137 } else { 138 v[0] = tmp.substring(0, tmp.indexOf(DOT)); 139 v[1] = tmp.substring(1 + tmp.indexOf(DOT), tmp.length()); 140 } 141 return v; 142 } 143 } | Popular Tags |