diff --git a/.travis.yml b/.travis.yml index 2f4f6616a..47f51a99d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,10 @@ before_script: - cargo install cargo-update || echo "cargo-update already installed" - cargo install cargo-travis || echo "cargo-travis already installed" - cargo install-update -a # updates cargo-travis, if the cached version is outdated - - rustup component add clippy rustfmt + - rustup component add clippy + # The license_template_path setting we use to verify copyright headers is + # only available on the nightly rustfmt. + - rustup toolchain install nightly && rustup component add --toolchain nightly rustfmt script: # Clippy must be run first, as its lints are only triggered during @@ -46,7 +49,7 @@ script: - travis-cargo clippy -- --all-targets --all-features -- -D warnings - travis-cargo build - travis-cargo test - - travis-cargo fmt -- -- --check + - travis-cargo --only nightly fmt -- -- --check --config-path <(echo 'license_template_path = "HEADER"') after_success: - cargo coveralls --verbose diff --git a/HEADER b/HEADER new file mode 100644 index 000000000..79fe4603f --- /dev/null +++ b/HEADER @@ -0,0 +1,11 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. \ No newline at end of file diff --git a/examples/cli.rs b/examples/cli.rs index c63ee3d69..f288fd138 100644 --- a/examples/cli.rs +++ b/examples/cli.rs @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #![warn(clippy::all)] use simple_logger; diff --git a/examples/parse_select.rs b/examples/parse_select.rs index 6a0a45063..d79ab26ed 100644 --- a/examples/parse_select.rs +++ b/examples/parse_select.rs @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #![warn(clippy::all)] use sqlparser::dialect::GenericSqlDialect; diff --git a/rustfmt.toml b/rustfmt.toml index 943db387b..edd0eecba 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1 @@ -# We use rustfmt's default settings to format the source code +# We use rustfmt's default settings to format the source code \ No newline at end of file diff --git a/src/dialect/ansi_sql.rs b/src/dialect/ansi_sql.rs index 939f85461..f537848b5 100644 --- a/src/dialect/ansi_sql.rs +++ b/src/dialect/ansi_sql.rs @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use crate::dialect::Dialect; #[derive(Debug)] diff --git a/src/dialect/generic_sql.rs b/src/dialect/generic_sql.rs index 09de47450..d6d7893a5 100644 --- a/src/dialect/generic_sql.rs +++ b/src/dialect/generic_sql.rs @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use crate::dialect::Dialect; #[derive(Debug)] diff --git a/src/dialect/keywords.rs b/src/dialect/keywords.rs index fb0873e14..fff69b5b0 100644 --- a/src/dialect/keywords.rs +++ b/src/dialect/keywords.rs @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + ///! This module defines /// 1) a list of constants for every keyword that /// can appear in SQLWord::keyword: diff --git a/src/dialect/mod.rs b/src/dialect/mod.rs index df6f26033..83b93833b 100644 --- a/src/dialect/mod.rs +++ b/src/dialect/mod.rs @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + mod ansi_sql; mod generic_sql; pub mod keywords; diff --git a/src/dialect/mssql.rs b/src/dialect/mssql.rs index 4ed1d00f4..c613a1502 100644 --- a/src/dialect/mssql.rs +++ b/src/dialect/mssql.rs @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use crate::dialect::Dialect; #[derive(Debug)] diff --git a/src/dialect/postgresql.rs b/src/dialect/postgresql.rs index 5433b440c..1c11d8a37 100644 --- a/src/dialect/postgresql.rs +++ b/src/dialect/postgresql.rs @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use crate::dialect::Dialect; #[derive(Debug)] diff --git a/src/lib.rs b/src/lib.rs index 420e9c3f6..cd2331525 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,3 @@ -// Copyright 2018 Grove Enterprises LLC -// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/src/sqlast/mod.rs b/src/sqlast/mod.rs index 9431cce16..3b952b0ae 100644 --- a/src/sqlast/mod.rs +++ b/src/sqlast/mod.rs @@ -1,5 +1,3 @@ -// Copyright 2018 Grove Enterprises LLC -// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/src/sqlast/query.rs b/src/sqlast/query.rs index 663e0e508..776d1f2ac 100644 --- a/src/sqlast/query.rs +++ b/src/sqlast/query.rs @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use super::*; /// The most complete variant of a `SELECT` query expression, optionally diff --git a/src/sqlast/sql_operator.rs b/src/sqlast/sql_operator.rs index 173bc80da..d080c7b1b 100644 --- a/src/sqlast/sql_operator.rs +++ b/src/sqlast/sql_operator.rs @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + /// SQL Operator #[derive(Debug, Clone, PartialEq, Hash)] pub enum SQLOperator { diff --git a/src/sqlast/sqltype.rs b/src/sqlast/sqltype.rs index ba339d078..3f9c3f931 100644 --- a/src/sqlast/sqltype.rs +++ b/src/sqlast/sqltype.rs @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use super::SQLObjectName; /// SQL data types diff --git a/src/sqlast/table_key.rs b/src/sqlast/table_key.rs new file mode 100644 index 000000000..92544ef6a --- /dev/null +++ b/src/sqlast/table_key.rs @@ -0,0 +1,73 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use super::{SQLIdent, SQLObjectName}; + +#[derive(Debug, Clone, PartialEq)] +pub enum AlterOperation { + AddConstraint(TableKey), + RemoveConstraint { name: SQLIdent }, +} + +impl ToString for AlterOperation { + fn to_string(&self) -> String { + match self { + AlterOperation::AddConstraint(table_key) => { + format!("ADD CONSTRAINT {}", table_key.to_string()) + } + AlterOperation::RemoveConstraint { name } => format!("REMOVE CONSTRAINT {}", name), + } + } +} + +#[derive(Debug, Clone, PartialEq)] +pub struct Key { + pub name: SQLIdent, + pub columns: Vec, +} + +#[derive(Debug, Clone, PartialEq)] +pub enum TableKey { + PrimaryKey(Key), + UniqueKey(Key), + Key(Key), + ForeignKey { + key: Key, + foreign_table: SQLObjectName, + referred_columns: Vec, + }, +} + +impl ToString for TableKey { + fn to_string(&self) -> String { + match self { + TableKey::PrimaryKey(ref key) => { + format!("{} PRIMARY KEY ({})", key.name, key.columns.join(", ")) + } + TableKey::UniqueKey(ref key) => { + format!("{} UNIQUE KEY ({})", key.name, key.columns.join(", ")) + } + TableKey::Key(ref key) => format!("{} KEY ({})", key.name, key.columns.join(", ")), + TableKey::ForeignKey { + key, + foreign_table, + referred_columns, + } => format!( + "{} FOREIGN KEY ({}) REFERENCES {}({})", + key.name, + key.columns.join(", "), + foreign_table.to_string(), + referred_columns.join(", ") + ), + } + } +} diff --git a/src/sqlast/value.rs b/src/sqlast/value.rs index 21bb199d4..46560bd25 100644 --- a/src/sqlast/value.rs +++ b/src/sqlast/value.rs @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use ordered_float::OrderedFloat; /// Primitive SQL values such as number and string diff --git a/src/sqlparser.rs b/src/sqlparser.rs index 1b1b83b61..6f093483b 100644 --- a/src/sqlparser.rs +++ b/src/sqlparser.rs @@ -1,5 +1,3 @@ -// Copyright 2018 Grove Enterprises LLC -// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/src/sqltokenizer.rs b/src/sqltokenizer.rs index e8b345973..056df5238 100644 --- a/src/sqltokenizer.rs +++ b/src/sqltokenizer.rs @@ -1,5 +1,3 @@ -// Copyright 2018 Grove Enterprises LLC -// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/src/test_utils.rs b/src/test_utils.rs index 16216bfe8..f884935a9 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use std::fmt::Debug; use super::dialect::*; diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 1c051ca00..3d8a4de04 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #![warn(clippy::all)] //! Test SQL syntax, which all sqlparser dialects must parse in the same way. //! diff --git a/tests/sqlparser_mssql.rs b/tests/sqlparser_mssql.rs index b49cfd78f..3b5f02dd1 100644 --- a/tests/sqlparser_mssql.rs +++ b/tests/sqlparser_mssql.rs @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #![warn(clippy::all)] //! Test SQL syntax specific to Microsoft's T-SQL. The parser based on the //! generic dialect is also tested (on the inputs it can handle). diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index f8753429c..b3f4a4459 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #![warn(clippy::all)] //! Test SQL syntax specific to PostgreSQL. The parser based on the //! generic dialect is also tested (on the inputs it can handle).