Skip to content

Commit

Permalink
fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Mar 16, 2024
1 parent b6ef46d commit 81ca4fd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
35 changes: 19 additions & 16 deletions sqlness/examples/interceptor-replace/simple/replace.result
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
-- SQLNESS REPLACE 00
SELECT 0;

SELECT 0;
SELECT 0

-- SQLNESS REPLACE 00
SELECT 00;

SELECT ;
SELECT

-- SQLNESS REPLACE 0 1
SELECT 0;

SELECT 1;
SELECT 1

-- example of capture group replacement
-- SQLNESS REPLACE (?P<y>\d{4})-(?P<m>\d{2})-(?P<d>\d{2}) $m/$d/$y
2012-03-14, 2013-01-01 and 2014-07-05;

03/14/2012, 01/01/2013 and 07/05/2014;
03/14/2012, 01/01/2013 and 07/05/2014

-- SQLNESS TEMPLATE {"name": "test"}
SELECT * FROM table where name = "test";
SELECT * FROM table where name = "{{name}}";

SELECT * FROM table where name = "test";
SELECT * FROM table where name = "test"

-- SQLNESS TEMPLATE {"aggr": ["sum", "avg", "count"]}
SELECT sum(c) from t ;

SELECT sum(c) from t ;

SELECT avg(c) from t ;
{% for item in aggr %}
SELECT {{item}}(c) from t {%if not loop.last %} {{sql_delimiter()}} {% endif %}
{% endfor %}
;

SELECT avg(c) from t ;
SELECT sum(c) from t

SELECT count(c) from t ;
SELECT avg(c) from t

SELECT count(c) from t ;
SELECT count(c) from t

-- SQLNESS TEMPLATE
INSERT INTO t (c) VALUES(1) , (2) , (3) , (4) ;
INSERT INTO t (c) VALUES
{% for num in range(1, 5) %}
({{ num }}) {%if not loop.last %} , {% endif %}
{% endfor %}
;

INSERT INTO t (c) VALUES(1) , (2) , (3) , (4) ;
INSERT INTO t (c) VALUES(1) , (2) , (3) , (4)

13 changes: 8 additions & 5 deletions sqlness/src/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,19 @@ impl Query {
writer.write_all(comment.as_bytes())?;
writer.write_all("\n".as_bytes())?;
}
for comment in &self.display_query {
writer.write_all(comment.as_bytes())?;
}
writer.write_all("\n\n".as_bytes())?;

let sql = self.concat_query_lines();
// An intercetor may generate multiple SQLs, so we need to split them.
for sql in sql.split(QUERY_DELIMITER) {
if !sql.trim().is_empty() {
let sql = format!("{sql};");
writer.write_all(sql.as_bytes())?;
writer.write_all("\n\n".as_bytes())?;

let mut result = db.query(context.clone(), sql).await.to_string();
let mut result = db
.query(context.clone(), format!("{sql};"))
.await
.to_string();
self.after_execute_intercept(&mut result);
self.write_result(writer, result)?;
}
Expand Down

0 comments on commit 81ca4fd

Please sign in to comment.