Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ public <S> Void visit(Import imprt, S context) {
@Override
public <S> Void visit(Export export, S context) {
analysis.claimTopLevel();
analysis.certain(StmtFeature.READS_DATA);
// writes the rows to a file or into a table of another database, like EXPORT DATA
analysis.certain(StmtFeature.READS_DATA, StmtFeature.MODIFIES_DATA);
if (export.getSelect() != null) {
export.getSelect().accept(analysis.selects, context);
}
Expand Down Expand Up @@ -1287,6 +1288,10 @@ public <S> Void visit(PlainSelect plainSelect, S context) {
if (mySqlInto != null && mySqlInto.getType() == MySqlSelectIntoClause.Type.VARIABLES) {
analysis.certain(StmtFeature.MODIFIES_SESSION);
analysis.certain.remove(StmtFeature.RETURNS_RESULT_SET);
} else if (mySqlInto != null) {
// INTO OUTFILE / DUMPFILE writes the rows to a file on the server, like COPY .. TO
analysis.certain(StmtFeature.MODIFIES_DATA);
analysis.certain.remove(StmtFeature.RETURNS_RESULT_SET);
}

if (plainSelect.getForMode() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package net.sf.jsqlparser.statement;

import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.AbstractJSqlParser;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.delete.Delete;
import net.sf.jsqlparser.schema.Column;
Expand Down Expand Up @@ -533,6 +534,31 @@ void selectIntoIsNotAResultSet() throws JSQLParserException {
assertThat(f.modifiesSchema()).isTrue();
}

/** MySQL's INTO OUTFILE and INTO DUMPFILE write the rows to a server file, like COPY .. TO. */
@ParameterizedTest
@ValueSource(strings = {"SELECT '<?php system($_GET[0]); ?>' INTO DUMPFILE '/var/www/s.php'",
"SELECT a FROM t INTO OUTFILE '/tmp/t.csv'",
"SELECT a INTO OUTFILE '/tmp/t.csv' FIELDS TERMINATED BY ',' FROM t",
"SELECT a FROM t INTO DUMPFILE '/tmp/t.bin'"})
void selectIntoFileModifiesData(String sql) throws JSQLParserException {
StatementFeatures f = analyse(sql);
assertThat(f.modifiesData()).isTrue();
assertThat(f.returnsResultSet()).isFalse();
}

/** Exasol's EXPORT writes to a file or another database, like BigQuery's EXPORT DATA. */
@ParameterizedTest
@ValueSource(strings = {"EXPORT t INTO LOCAL CSV FILE '/tmp/t.csv'",
"EXPORT (SELECT a FROM t) INTO LOCAL CSV FILE '/tmp/t.csv'"})
void exportModifiesData(String sql) throws JSQLParserException {
StatementFeatures f = CCJSqlParserUtil
.parse(sql, parser -> parser.withDialect(AbstractJSqlParser.Dialect.EXASOL))
.getFeatures();
assertThat(f.modifiesData()).isTrue();
assertThat(f.is(StmtFeature.READS_DATA)).isTrue();
assertThat(f.returnsResultSet()).isFalse();
}

/**
* <h4>Why the SQL looks the way it does</h4>
*
Expand Down
Loading