Skip to content

Commit 81ee7e4

Browse files
Merge pull request #1 from yuriy-glotanov/master
sql parse errors -> log
2 parents e85d5de + e796069 commit 81ee7e4

6 files changed

Lines changed: 33 additions & 45 deletions

File tree

src/main/java/su/interference/sql/SQLSelect.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ this software and associated documentation files (the "Software"), to deal in
4141

4242
public class SQLSelect implements SQLStatement {
4343
private static final String SELECT_CLAUSE = "SELECT";
44+
private static final String STREAM_CLAUSE = " STREAM ";
4445
private static final String DISTINCT_CLAUSE = " DISTINCT ";
4546
private static final String FROM_CLAUSE = " FROM ";
4647
private static final String WHERE_CLAUSE = " WHERE ";
@@ -55,13 +56,14 @@ public class SQLSelect implements SQLStatement {
5556
private SQLJoin join;
5657
private ArrayList<SQLNode> nodes;
5758

59+
private boolean stream;
5860
private boolean distinct;
5961
private boolean entityResult;
6062
private Table entityTable;
61-
private String SQLErrorText;
63+
private SQLException sqlException;
6264

63-
public String getSQLErrorText() {
64-
return SQLErrorText;
65+
public SQLException getSQLException() {
66+
return sqlException;
6567
}
6668

6769
public SQLSelect () {
@@ -79,10 +81,11 @@ public SQLSelect (String sql, Cursor cur, Session s) {
7981
try {
8082
parseSQL(sql, cur, s);
8183
} catch (SQLException e) {
82-
SQLErrorText = e.getSQLErrorText();
84+
sqlException = e;
85+
logger.error(e.getClass().getSimpleName()+" thrown during parse of sql statement: "+sql);
8386
} catch (Exception e) {
84-
e.printStackTrace();
85-
SQLErrorText = e.getMessage();
87+
sqlException = new SQLException(e.getMessage());
88+
logger.error(e.getClass().getSimpleName()+" thrown during parse of sql statement: "+sql);
8689
}
8790
}
8891

@@ -151,10 +154,13 @@ private final void parseSQL (String s, Cursor cur, Session sn) throws Exception
151154
if (!SQL.startsWith(SELECT_CLAUSE)) {
152155
throw new InvalidSQLStatement();
153156
}
154-
if (SQL.indexOf(DISTINCT_CLAUSE)>6) {
157+
if (SQL.indexOf(STREAM_CLAUSE) >6 ) {
158+
this.stream = true;
159+
}
160+
if (SQL.indexOf(DISTINCT_CLAUSE) >6 ) {
155161
this.distinct = true;
156162
}
157-
if (SQL.indexOf(FROM_CLAUSE) < SELECT_CLAUSE.length()+1) {
163+
if (SQL.indexOf(FROM_CLAUSE) < SELECT_CLAUSE.length() + 1) {
158164
throw new MissingFromClause();
159165
}
160166
if (sql.substring(SELECT_CLAUSE.length(), SQL.indexOf(" FROM ")).trim().equals("")) {

src/main/java/su/interference/sql/SQLStatement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ this software and associated documentation files (the "Software"), to deal in
3636
public interface SQLStatement {
3737

3838
DataSet executeSQL (Session s) throws SQLException;
39-
String getSQLErrorText();
39+
SQLException getSQLException();
4040
CList getCols();
4141

4242
}

src/main/java/su/interference/sql/SQLSystem.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -114,27 +114,7 @@ public SQLSystem (String sql, Session s) {
114114
public DataSet executeSQL (Session s) throws SQLException {
115115

116116
String message = "";
117-
String action = "";
118-
String actionName = "";
119-
boolean nowrap = false;
120-
boolean command = true;
121-
/*
122-
if (stmt.equals("initStorage")) {
123-
Storage.getStorage().initStorage();
124-
}
125-
if (stmt.equals("checkStorage")) {
126-
Storage.getStorage().checkStorage();
127-
}
128-
if (stmt.equals("openStorage")) {
129-
Storage.getStorage().openStorage();
130-
}
131-
if (stmt.equals("closeStorage")) {
132-
Storage.getStorage().closeStorage();
133-
}
134-
if (stmt.equals("dropStorage")) {
135-
Storage.getStorage().dropStorage();
136-
}
137-
*/
117+
138118
try {
139119
/*
140120
if (stmt.equals("createInstance")) {
@@ -202,7 +182,7 @@ public CList getCols() {
202182
return null;
203183
}
204184

205-
public String getSQLErrorText() {
185+
public SQLException getSQLException() {
206186
return null;
207187
}
208188

src/main/java/su/interference/sqlexception/SQLException.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ this software and associated documentation files (the "Software"), to deal in
3030
*/
3131

3232
public class SQLException extends Exception {
33-
private String SQLErrorText;
33+
private String message;
3434

3535
public SQLException () {
3636

3737
}
3838

3939
public SQLException (String e) {
40-
SQLErrorText = e;
40+
message = e;
4141
}
4242

43-
public String getSQLErrorText () {
44-
return SQLErrorText;
43+
public String getSQLExceptionMessage () {
44+
return message;
4545
}
4646

4747
}

src/main/java/su/interference/transport/SQLEvent.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,18 @@ public EventResult process() {
112112
//s.startStatement();
113113
final SQLStatement sql = cur == null ? SQLStatementFactory.getInstance(this.sql, s) : SQLStatementFactory.getInstance(this.sql, cur, s);
114114
//todo temp solution
115-
try {
116-
if (sql instanceof SQLSystem) {
117-
sql.executeSQL(s);
115+
if (sql.getSQLException() != null) {
116+
return new EventResult(TransportCallback.FAILURE, cur.getCursorId(), null, sql.getSQLException());
117+
} else {
118+
try {
119+
if (sql instanceof SQLSystem) {
120+
sql.executeSQL(s);
121+
}
122+
} catch (SQLException e) {
123+
return new EventResult(TransportCallback.FAILURE, cur.getCursorId(), null, e);
118124
}
119-
} catch (SQLException e) {
120-
return new EventResult(TransportCallback.FAILURE, cur.getCursorId(), null, e);
121-
}
122-
//todo process exceptions
123-
if (sql.getSQLErrorText() != null) {
124-
return new EventResult(TransportCallback.FAILURE, cur.getCursorId(), null, new RuntimeException(sql.getSQLErrorText()));
125+
return new EventResult(TransportCallback.SUCCESS, cur.getCursorId(), null, null);
125126
}
126-
return new EventResult(TransportCallback.SUCCESS, cur.getCursorId(), null, null);
127127
}
128128
}
129129

src/main/java/su/interference/transport/SyncFrameEvent.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ public synchronized int rframe2(SyncFrame[] sb) throws Exception {
7878
for (DataFile f : dfs) {
7979
final int order = (f.getFileId() % Storage.MAX_NODES) % Config.getConfig().FILES_AMOUNT;
8080
if (order == allocOrder) {
81+
//final LLT llt = LLT.getLLT();
8182
bd = t.createNewFrame(null, f.getFileId(), b.getFrameType(), b.getAllocId(), b.isStarted(), false, true, s, null);
83+
//llt.commit();
8284
//bd.setAllocId(b.getAllocId());
8385
bd.setFrame(null);
8486
b.setDf(f);

0 commit comments

Comments
 (0)