001: /*
002: * Created on Dec 20, 2004
003: *
004: * @author ctaylor
005: *
006: */
007: package com.pk;
008:
009: import java.sql.Connection;
010: import java.sql.SQLException;
011: import java.util.Vector;
012:
013: /**
014: * @author ctaylor
015: *
016: */
017: public class MicrosoftSQLDialect implements DatabaseDialect {
018:
019: /* (non-Javadoc)
020: * @see com.pk.DatabaseDialect#getKeywords()
021: */
022: public Vector getKeywords() {
023: Vector keywords = new Vector();
024: keywords.addElement("select");
025: keywords.addElement("set");
026: keywords.addElement("or");
027: keywords.addElement("and");
028: keywords.addElement("where");
029: keywords.addElement("from");
030: keywords.addElement("insert");
031: keywords.addElement("update");
032: keywords.addElement("order");
033: keywords.addElement("by");
034: keywords.addElement("close");
035: keywords.addElement("commit");
036: keywords.addElement("rollback");
037: keywords.addElement("create");
038: keywords.addElement("database");
039: keywords.addElement("drop");
040: keywords.addElement("table");
041: keywords.addElement("view");
042: keywords.addElement("join");
043: keywords.addElement("into");
044: keywords.addElement("between");
045: keywords.addElement("values");
046: keywords.addElement("alter");
047: keywords.addElement("add");
048: keywords.addElement("modify");
049: keywords.addElement("close");
050: keywords.addElement("distinct");
051: keywords.addElement("index");
052: keywords.addElement("grant");
053: keywords.addElement("delete");
054: keywords.addElement("group");
055: keywords.addElement("as");
056: keywords.addElement("having");
057: keywords.addElement("delete");
058: keywords.addElement("like");
059: keywords.addElement("unique");
060: keywords.addElement("primary");
061: keywords.addElement("key");
062: keywords.addElement("not");
063: keywords.addElement("null");
064: keywords.addElement("asc");
065: keywords.addElement("desc");
066: keywords.addElement("revoke");
067: keywords.addElement("remark");
068: keywords.addElement("exists");
069: keywords.addElement("union");
070: keywords.addElement("decode");
071:
072: return keywords;
073: }
074:
075: /* (non-Javadoc)
076: * @see com.pk.DatabaseDialect#getTableInfoSQLString(java.lang.String, com.pk.ConnectionInformation)
077: */
078: public String getTableInfoSQLString(String argTableName,
079: ConnectionInformation argConnectionInformation) {
080: return "select COLUMN_NAME, IS_NULLABLE, DATA_TYPE, case when CHARACTER_MAXIMUM_LENGTH is not null then CHARACTER_MAXIMUM_LENGTH when NUMERIC_PRECISION is not null then str(NUMERIC_PRECISION) when DATETIME_PRECISION is not null then str(DATETIME_PRECISION) end as 'SIZE', NUMERIC_PRECISION as FIELD_PRECISION from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = '"
081: + argTableName + "'";
082: }
083:
084: /* (non-Javadoc)
085: * @see com.pk.DatabaseDialect#getIndexInfoSQLString(java.lang.String, com.pk.ConnectionInformation)
086: */
087: public String getIndexInfoSQLString(String argTableName,
088: ConnectionInformation argConnectionInformation) {
089: // TODO Auto-generated method stub
090: return null;
091: }
092:
093: /* (non-Javadoc)
094: * @see com.pk.DatabaseDialect#getProcedureInfoSQLString(java.lang.String, com.pk.ConnectionInformation)
095: */
096: public String getProcedureInfoSQLString(String argProcedureName,
097: ConnectionInformation argConnectionInformation) {
098: return "select ROUTINE_NAME, ROUTINE_DEFINITION from INFORMATION_SCHEMA.ROUTINES where ROUTINE_TYPE = 'PROCEDURE' and ROUTINE_NAME = "
099: + argProcedureName;
100: }
101:
102: /* (non-Javadoc)
103: * @see com.pk.DatabaseDialect#getPackageInfoSQLString(java.lang.String, com.pk.ConnectionInformation)
104: */
105: public String getPackageInfoSQLString(String argProcedureName,
106: ConnectionInformation argConnectionInformation) {
107: // TODO Auto-generated method stub
108: return null;
109: }
110:
111: /* (non-Javadoc)
112: * @see com.pk.DatabaseDialect#isSelectStatement(java.lang.String)
113: */
114: public boolean isSelectStatement(String argStatement) {
115: boolean isSelect = false;
116: if (argStatement.toUpperCase().startsWith("SELECT")
117: || argStatement.toUpperCase().startsWith("SHOW")) {
118: isSelect = true;
119: }
120: return isSelect;
121: }
122:
123: /* (non-Javadoc)
124: * @see com.pk.DatabaseDialect#isDescribeStatement(java.lang.String)
125: */
126: public boolean isDescribeStatement(String argStatement) {
127: boolean isDescribe = false;
128: if (argStatement.toUpperCase().startsWith("DESC")) {
129: isDescribe = true;
130: }
131: return isDescribe;
132: }
133:
134: /* (non-Javadoc)
135: * @see com.pk.DatabaseDialect#getDescribeSQLString(java.lang.String, com.pk.ConnectionInformation)
136: */
137: public String getDescribeSQLString(String argQuery,
138: ConnectionInformation argConnectionInformation) {
139: String tName = argQuery.substring(5);
140: return getTableInfoSQLString(tName, argConnectionInformation);
141: }
142:
143: /* (non-Javadoc)
144: * @see com.pk.DatabaseDialect#doExecutePlan(java.lang.String, com.pk.ConnectionInformation, java.sql.Connection)
145: */
146: public String doExecutePlan(String argStatement,
147: ConnectionInformation argConnectionInformation,
148: Connection argConnection) throws SQLException {
149: // TODO Auto-generated method stub
150: return null;
151: }
152:
153: }
|