diff --git a/datagear-web/src/main/java/org/datagear/web/sqlpad/SqlpadCometdService.java b/datagear-web/src/main/java/org/datagear/web/sqlpad/SqlpadCometdService.java
index a34c1e31..9e2778a4 100644
--- a/datagear-web/src/main/java/org/datagear/web/sqlpad/SqlpadCometdService.java
+++ b/datagear-web/src/main/java/org/datagear/web/sqlpad/SqlpadCometdService.java
@@ -11,6 +11,7 @@ import org.cometd.server.AbstractService;
import org.datagear.web.OperationMessage;
import org.datagear.web.sqlpad.SqlpadExecutionService.SQLExecutionStat;
import org.datagear.web.sqlpad.SqlpadExecutionService.SqlCommand;
+import org.datagear.web.sqlpad.SqlpadExecutionService.SqlResultType;
import org.datagear.web.util.SqlScriptParser.SqlStatement;
/**
@@ -45,9 +46,28 @@ public class SqlpadCometdService extends AbstractService
* @param sqlStatement
* @param sqlStatementCount
*/
- public void sendSuccessMessage(ServerChannel channel, SqlStatement sqlStatement, int sqlStatementIndex)
+ public void sendExecuteSQLSuccessMessage(ServerChannel channel, SqlStatement sqlStatement, int sqlStatementIndex)
{
- channel.publish(getServerSession(), new SqlSuccessMessageData(sqlStatement, sqlStatementIndex));
+ channel.publish(getServerSession(),
+ new SqlSuccessMessageData(sqlStatement, sqlStatementIndex, SqlResultType.NONE));
+ }
+
+ /**
+ * 发送SQL执行成功消息。
+ *
+ * @param channel
+ * @param sqlStatement
+ * @param sqlStatementIndex
+ * @param updateCount
+ */
+ public void sendExecuteSQLSuccessMessage(ServerChannel channel, SqlStatement sqlStatement, int sqlStatementIndex,
+ int updateCount)
+ {
+ SqlSuccessMessageData sqlSuccessMessageData = new SqlSuccessMessageData(sqlStatement, sqlStatementIndex,
+ SqlResultType.UPDATE_COUNT);
+ sqlSuccessMessageData.setUpdateCount(updateCount);
+
+ channel.publish(getServerSession(), sqlSuccessMessageData);
}
/**
@@ -277,16 +297,23 @@ public class SqlpadCometdService extends AbstractService
/** SQL语句索引 */
private int sqlStatementIndex;
+ /** SQL结果类型 */
+ private SqlResultType sqlResultType = SqlResultType.NONE;
+
+ /** 更新数目 */
+ private int updateCount = -1;
+
public SqlSuccessMessageData()
{
super(TYPE);
}
- public SqlSuccessMessageData(SqlStatement sqlStatement, int sqlStatementIndex)
+ public SqlSuccessMessageData(SqlStatement sqlStatement, int sqlStatementIndex, SqlResultType sqlResultType)
{
super(TYPE);
this.sqlStatement = sqlStatement;
this.sqlStatementIndex = sqlStatementIndex;
+ this.sqlResultType = sqlResultType;
}
public SqlStatement getSqlStatement()
@@ -308,6 +335,26 @@ public class SqlpadCometdService extends AbstractService
{
this.sqlStatementIndex = sqlStatementIndex;
}
+
+ public SqlResultType getSqlResultType()
+ {
+ return sqlResultType;
+ }
+
+ public void setSqlResultType(SqlResultType sqlResultType)
+ {
+ this.sqlResultType = sqlResultType;
+ }
+
+ public int getUpdateCount()
+ {
+ return updateCount;
+ }
+
+ public void setUpdateCount(int updateCount)
+ {
+ this.updateCount = updateCount;
+ }
}
protected static class ExceptionMessageData extends MessageData
diff --git a/datagear-web/src/main/java/org/datagear/web/sqlpad/SqlpadExecutionService.java b/datagear-web/src/main/java/org/datagear/web/sqlpad/SqlpadExecutionService.java
index 5b899fdd..7b5a938d 100644
--- a/datagear-web/src/main/java/org/datagear/web/sqlpad/SqlpadExecutionService.java
+++ b/datagear-web/src/main/java/org/datagear/web/sqlpad/SqlpadExecutionService.java
@@ -406,11 +406,8 @@ public class SqlpadExecutionService
try
{
- execute(cn, st, sqlStatement.getSql());
-
+ execute(cn, st, sqlStatement, i);
sqlExecutionStat.increaseSuccessCount();
-
- this.sqlpadCometdService.sendSuccessMessage(_sqlpadServerChannel, sqlStatement, i);
}
catch (SQLException e)
{
@@ -612,11 +609,35 @@ public class SqlpadExecutionService
* @param sql
* @throws SQLException
*/
- protected void execute(Connection cn, Statement st, String sql) throws SQLException
+ protected void execute(Connection cn, Statement st, SqlStatement sqlStatement, int sqlStatementIndex)
+ throws SQLException
{
- // TODO 执行SQL
+ boolean isResultSet = st.execute(sqlStatement.getSql());
- st.execute(sql);
+ // 查询操作
+ if (isResultSet)
+ {
+ // TODO 处理查询操作
+ this.sqlpadCometdService.sendExecuteSQLSuccessMessage(this._sqlpadServerChannel, sqlStatement,
+ sqlStatementIndex);
+ }
+ else
+ {
+ int updateCount = st.getUpdateCount();
+
+ // 更新操作
+ if (updateCount > -1)
+ {
+ this.sqlpadCometdService.sendExecuteSQLSuccessMessage(this._sqlpadServerChannel, sqlStatement,
+ sqlStatementIndex, updateCount);
+ }
+ // 其他操作
+ else
+ {
+ this.sqlpadCometdService.sendExecuteSQLSuccessMessage(this._sqlpadServerChannel, sqlStatement,
+ sqlStatementIndex);
+ }
+ }
try
{
@@ -801,4 +822,22 @@ public class SqlpadExecutionService
/** 停止 */
STOP
}
+
+ /**
+ * SQL执行结果类型。
+ *
+ * @author datagear@163.com
+ *
+ */
+ public static enum SqlResultType
+ {
+ /** 结果集 */
+ RESULT_SET,
+
+ /** 更新数目 */
+ UPDATE_COUNT,
+
+ /** 无结果 */
+ NONE
+ }
}
diff --git a/datagear-web/src/main/resources/locales/datagear.properties b/datagear-web/src/main/resources/locales/datagear.properties
index bf145df2..685a7344 100644
--- a/datagear-web/src/main/resources/locales/datagear.properties
+++ b/datagear-web/src/main/resources/locales/datagear.properties
@@ -379,4 +379,5 @@ sqlpad.sqlExecutionStat.infoNoDuration=SQL\u603B\u8BA1{0}\u6761\uFF0C\u6210\u529
sqlpad.sqlExecutionStat.infoSuffixDuration.H.M=\uFF0C\u7528\u65F6{0}\u5C0F\u65F6{1}\u5206
sqlpad.sqlExecutionStat.infoSuffixDuration.M.S=\uFF0C\u7528\u65F6{0}\u5206{1}\u79D2
sqlpad.sqlExecutionStat.infoSuffixDuration.S.MS=\uFF0C\u7528\u65F6{0}\u79D2{1}\u6BEB\u79D2
-sqlpad.sqlExecutionStat.infoSuffixDuration.MS=\uFF0C\u7528\u65F6{0}\u6BEB\u79D2
\ No newline at end of file
+sqlpad.sqlExecutionStat.infoSuffixDuration.MS=\uFF0C\u7528\u65F6{0}\u6BEB\u79D2
+sqlpad.affectDataRowCount=\u5F71\u54CD\u4E86 {0} \u884C\u6570\u636E
\ No newline at end of file
diff --git a/datagear-web/src/main/webapp/WEB-INF/view/sqlpad/sqlpad.ftl b/datagear-web/src/main/webapp/WEB-INF/view/sqlpad/sqlpad.ftl
index d6fc558c..c7605514 100644
--- a/datagear-web/src/main/webapp/WEB-INF/view/sqlpad/sqlpad.ftl
+++ b/datagear-web/src/main/webapp/WEB-INF/view/sqlpad/sqlpad.ftl
@@ -215,7 +215,7 @@ select count(*) from t_order where id = 3 and name = 'jack';
return;
$("["+(sqlStatementIndex + 1)+"]").appendTo($msgContent);
- var $sqlValue = $("").text($.truncateIf(sqlStatement.sql, "...", 38)).appendTo($msgContent);
+ var $sqlValue = $("").text($.truncateIf(sqlStatement.sql, "...", 100)).appendTo($msgContent);
<#assign messageArgs=['"+(sqlStatement.startRow+1)+"', '"+sqlStatement.startColumn+"', '"+(sqlStatement.endRow+1)+"', '"+sqlStatement.endColumn+"'] />
$sqlValue.attr("title", "<@spring.messageArgs code='sqlpad.executionSqlselectionRange' args=messageArgs />");
@@ -300,6 +300,19 @@ select count(*) from t_order where id = 3 and name = 'jack';
$msgDiv.addClass("execution-success");
po.appendSqlStatementMessage($msgContent, msgData.sqlStatement, msgData.sqlStatementIndex);
+
+ if(msgData.sqlResultType = "UPDATE_COUNT")
+ {
+ <#assign messageArgs=['"+msgData.updateCount+"'] />
+ $("").text("<@spring.messageArgs code='sqlpad.affectDataRowCount' args=messageArgs />")
+ .appendTo($msgContent);
+ }
+ else if(msgData.sqlResultType = "RESULT_SET")
+ {
+
+ }
+ else
+ ;
}
else if(msgDataType == "SQLEXCEPTION")
{
diff --git a/datagear-web/src/main/webapp/static/theme/common.css b/datagear-web/src/main/webapp/static/theme/common.css
index ade4b680..f8b40906 100644
--- a/datagear-web/src/main/webapp/static/theme/common.css
+++ b/datagear-web/src/main/webapp/static/theme/common.css
@@ -1360,6 +1360,13 @@ table.dataTable tbody tr .column-check .row-data-state .ui-icon{
.page-sqlpad .content .content-result .execution-message .message-content span{
margin-right: 0.41em;
}
+.page-sqlpad .content .content-result .execution-message .message-content .sql-value{
+ display: inline-block;
+ width: 30%;
+ overflow: hidden;
+ white-space: nowrap;
+ vertical-align: bottom;
+}
.page-sqlpad .foot{
position: absolute;
width: 100%;