Skip to content

Commit

Permalink
fix(OracleGrammar): Only use batch insert syntax when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed May 14, 2021
1 parent b7deb9a commit 9707f03
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 3 additions & 1 deletion models/Grammars/OracleGrammar.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ component extends="qb.models.Grammars.BaseGrammar" singleton {
throw( type = "UnsupportedOperation", message = "This grammar does not support a RETURNING clause" );
}

var multiple = arguments.values.len() > 1;

var columnsString = arguments.columns
.map( function( column ) {
return wrapColumn( column.formatted );
Expand All @@ -130,7 +132,7 @@ component extends="qb.models.Grammars.BaseGrammar" singleton {
.toList( ", " ) & ")";
} )
.toList( " " );
return trim( "INSERT ALL #placeholderString# SELECT 1 FROM dual" );
return trim( "INSERT#multiple ? " ALL" : ""# #placeholderString##multiple ? " SELECT 1 FROM dual" : ""#" );
}

/**
Expand Down
13 changes: 5 additions & 8 deletions tests/specs/Query/OracleQueryBuilderSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -610,14 +610,11 @@ component extends="tests.resources.AbstractQueryBuilderSpec" {
}

function insertSingleColumn() {
return { sql: "INSERT ALL INTO ""USERS"" (""EMAIL"") VALUES (?) SELECT 1 FROM dual", bindings: [ "foo" ] };
return { sql: "INSERT INTO ""USERS"" (""EMAIL"") VALUES (?)", bindings: [ "foo" ] };
}

function insertMultipleColumns() {
return {
sql: "INSERT ALL INTO ""USERS"" (""EMAIL"", ""NAME"") VALUES (?, ?) SELECT 1 FROM dual",
bindings: [ "foo", "bar" ]
};
return { sql: "INSERT INTO ""USERS"" (""EMAIL"", ""NAME"") VALUES (?, ?)", bindings: [ "foo", "bar" ] };
}

function batchInsert() {
Expand All @@ -629,14 +626,14 @@ component extends="tests.resources.AbstractQueryBuilderSpec" {

function insertWithRaw() {
return {
sql: "INSERT ALL INTO ""USERS"" (""CREATED_DATE"", ""EMAIL"") VALUES (now(), ?) SELECT 1 FROM dual",
sql: "INSERT INTO ""USERS"" (""CREATED_DATE"", ""EMAIL"") VALUES (now(), ?)",
bindings: [ "john@example.com" ]
};
}

function insertWithNull() {
return {
sql: "INSERT ALL INTO ""USERS"" (""EMAIL"", ""OPTIONAL_FIELD"") VALUES (?, ?) SELECT 1 FROM dual",
sql: "INSERT INTO ""USERS"" (""EMAIL"", ""OPTIONAL_FIELD"") VALUES (?, ?)",
bindings: [ "john@example.com", "NULL" ]
};
}
Expand Down Expand Up @@ -672,7 +669,7 @@ component extends="tests.resources.AbstractQueryBuilderSpec" {
}

function updateOrInsertNotExists() {
return { sql: "INSERT ALL INTO ""USERS"" (""NAME"") VALUES (?) SELECT 1 FROM dual", bindings: [ "baz" ] };
return { sql: "INSERT INTO ""USERS"" (""NAME"") VALUES (?)", bindings: [ "baz" ] };
}

function updateOrInsertExists() {
Expand Down

0 comments on commit 9707f03

Please sign in to comment.