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 f2e08a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
17 changes: 10 additions & 7 deletions sqlness/examples/interceptor-replace/simple/replace.result
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,28 @@ SELECT 1;
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";

-- SQLNESS TEMPLATE {"aggr": ["sum", "avg", "count"]}
SELECT sum(c) from t ;
{% for item in aggr %}
SELECT {{item}}(c) from t {%if not loop.last %} {{sql_delimiter()}} {% endif %}
{% endfor %}
;

SELECT sum(c) from t ;

SELECT avg(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) ;

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 f2e08a8

Please sign in to comment.