github.com/dolthub/go-mysql-server@v0.18.0/sql/errors.go (about) 1 // Copyright 2020-2021 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package sql 16 17 import ( 18 "fmt" 19 "strings" 20 21 "github.com/dolthub/vitess/go/mysql" 22 "gopkg.in/src-d/go-errors.v1" 23 ) 24 25 var ( 26 // ErrSyntaxError is returned when a syntax error in vitess is encountered. 27 ErrSyntaxError = errors.NewKind("%s") 28 29 // ErrUnsupportedFeature is thrown when a feature is not already supported 30 ErrUnsupportedFeature = errors.NewKind("unsupported feature: %s") 31 32 // ErrReadOnly is returned when the engine has been set to Read Only but a write operation was attempted. 33 ErrReadOnly = errors.NewKind("database server is set to read only mode") 34 35 // ErrInvalidSystemVariableValue is returned when a system variable is assigned a value that it does not accept. 36 ErrInvalidSystemVariableValue = errors.NewKind("Variable '%s' can't be set to the value of '%v'") 37 38 // ErrSystemVariableCodeFail is returned when failing to encode/decode a system variable. 39 ErrSystemVariableCodeFail = errors.NewKind("unable to encode/decode value '%v' for '%s'") 40 41 // ErrInvalidType is thrown when there is an unexpected type at some part of 42 // the execution tree. 43 ErrInvalidType = errors.NewKind("invalid type: %s") 44 45 // ErrTableAlreadyExists is thrown when someone tries to create a 46 // table with a name of an existing one 47 ErrTableAlreadyExists = errors.NewKind("table with name %s already exists") 48 49 // ErrTableNotFound is returned when the table is not available from the 50 // current scope. 51 ErrTableNotFound = errors.NewKind("table not found: %s") 52 53 // ErrInvalidRefInView is returned when querying existing view that references non-existent table. 54 // Creating new view or updating existing view to reference non-existent table/view do not apply here. 55 ErrInvalidRefInView = errors.NewKind("View '%s.%s' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them") 56 57 // ErrUnknownTable is returned when the non-table name is used for table actions. 58 ErrUnknownTable = errors.NewKind("Unknown table '%s'") 59 60 // ErrTableColumnNotFound is thrown when a column named cannot be found in scope 61 ErrTableColumnNotFound = errors.NewKind("table %q does not have column %q") 62 63 // ErrColumnNotFound is returned when the column does not exist in any 64 // table in scope. 65 ErrColumnNotFound = errors.NewKind("column %q could not be found in any table in scope") 66 67 // ErrAmbiguousColumnName is returned when there is a column reference that 68 // is present in more than one table. 69 ErrAmbiguousColumnName = errors.NewKind("ambiguous column name %q, it's present in all these tables: %v") 70 71 // ErrAmbiguousColumnOrAliasName is returned when a column or alias name can't be qualified to a table or alias definition 72 ErrAmbiguousColumnOrAliasName = errors.NewKind("ambiguous column or alias name %q") 73 74 // ErrAmbiguousColumnInOrderBy is returned when an order by column is ambiguous 75 ErrAmbiguousColumnInOrderBy = errors.NewKind("Column %q in order clause is ambiguous") 76 77 // ErrColumnExists is returned when an ALTER TABLE statement would create a duplicate column 78 ErrColumnExists = errors.NewKind("Column %q already exists") 79 80 // ErrCreateTableNotSupported is thrown when the database doesn't support table creation 81 ErrCreateTableNotSupported = errors.NewKind("tables cannot be created on database %s") 82 83 // ErrDropTableNotSupported is thrown when the database doesn't support dropping tables 84 ErrDropTableNotSupported = errors.NewKind("tables cannot be dropped on database %s") 85 86 // ErrRenameTableNotSupported is thrown when the database doesn't support renaming tables 87 ErrRenameTableNotSupported = errors.NewKind("tables cannot be renamed on database %s") 88 89 // ErrDatabaseCollationsNotSupported is thrown when a database does not allow updating its collation 90 ErrDatabaseCollationsNotSupported = errors.NewKind("database %s does not support collation operations") 91 92 // ErrTableCreatedNotFound is thrown when a table is created from CREATE TABLE but cannot be found immediately afterward 93 ErrTableCreatedNotFound = errors.NewKind("table was created but could not be found") 94 95 // ErrUnexpectedRowLength is thrown when the obtained row has more columns than the schema 96 ErrUnexpectedRowLength = errors.NewKind("expected %d values, got %d") 97 98 // ErrInvalidChildrenNumber is returned when the WithChildren method of a 99 // node or expression is called with an invalid number of arguments. 100 ErrInvalidChildrenNumber = errors.NewKind("%T: invalid children number, got %d, expected %d") 101 102 // ErrInvalidExpressionNumber is returned when the WithExpression method of a node 103 // is called with an invalid number of arguments. 104 ErrInvalidExpressionNumber = errors.NewKind("%T: invalid expression number, got %d, expected %d") 105 106 // ErrInvalidChildType is returned when the WithChildren method of a 107 // node or expression is called with an invalid child type. This error is indicative of a bug. 108 ErrInvalidChildType = errors.NewKind("%T: invalid child type, got %T, expected %T") 109 110 // ErrInvalidJSONText is returned when a JSON string cannot be parsed or unmarshalled 111 ErrInvalidJSONText = errors.NewKind("Invalid JSON text: %s") 112 113 // ErrDeleteRowNotFound is returned when row being deleted was not found 114 ErrDeleteRowNotFound = errors.NewKind("row was not found when attempting to delete") 115 116 // ErrDuplicateAliasOrTable should be returned when a query contains a duplicate alias / table name. 117 ErrDuplicateAliasOrTable = errors.NewKind("Not unique table/alias: %s") 118 119 // ErrPrimaryKeyViolation is returned when a primary key constraint is violated 120 // This is meant to wrap a sql.UniqueKey error, which provides the key string 121 ErrPrimaryKeyViolation = errors.NewKind("duplicate primary key given") 122 123 // ErrUniqueKeyViolation is returned when a unique key constraint is violated 124 // This is meant to wrap a sql.UniqueKey error, which provides the key string 125 ErrUniqueKeyViolation = errors.NewKind("duplicate unique key given") 126 127 // ErrMisusedAlias is returned when a alias is defined and used in the same projection. 128 ErrMisusedAlias = errors.NewKind("column %q does not exist in scope, but there is an alias defined in" + 129 " this projection with that name. Aliases cannot be used in the same projection they're defined in") 130 131 // ErrInvalidAsOfExpression is returned when an expression for AS OF cannot be used 132 ErrInvalidAsOfExpression = errors.NewKind("expression %s cannot be used in AS OF") 133 134 // ErrIncompatibleDefaultType is returned when a provided default cannot be coerced into the type of the column 135 ErrIncompatibleDefaultType = errors.NewKind("incompatible type for default value") 136 137 // ErrColumnDefaultDatetimeOnlyFunc is returned when a non datetime/timestamp column attempts to declare now/current_timestamp as a default value literal. 138 ErrColumnDefaultDatetimeOnlyFunc = errors.NewKind("only datetime/timestamp may declare default values of now()/current_timestamp() without surrounding parentheses") 139 140 // ErrColumnDefaultSubquery is returned when a default value contains a subquery. 141 ErrColumnDefaultSubquery = errors.NewKind("default value on column `%s` may not contain subqueries") 142 143 // ErrInvalidColumnDefaultValue is returned when column default function value is not wrapped in parentheses for column types excluding datetime and timestamp 144 ErrInvalidColumnDefaultValue = errors.NewKind("Invalid default value for '%s'") 145 146 // ErrInvalidDefaultValueOrder is returned when a default value references a column that comes after it and contains a default expression. 147 ErrInvalidDefaultValueOrder = errors.NewKind(`default value of column "%s" cannot refer to a column defined after it if those columns have an expression default value`) 148 149 // ErrColumnDefaultReturnedNull is returned when a default expression evaluates to nil but the column is non-nullable. 150 ErrColumnDefaultReturnedNull = errors.NewKind(`default value attempted to return null but column is non-nullable`) 151 152 // ErrDropColumnReferencedInDefault is returned when a column cannot be dropped as it is referenced by another column's default value. 153 ErrDropColumnReferencedInDefault = errors.NewKind(`cannot drop column "%s" as default value of column "%s" references it`) 154 155 // ErrTriggersNotSupported is returned when attempting to create a trigger on a database that doesn't support them 156 ErrTriggersNotSupported = errors.NewKind(`database "%s" doesn't support triggers`) 157 158 // ErrTriggerCreateStatementInvalid is returned when a TriggerDatabase returns a CREATE TRIGGER statement that is invalid 159 ErrTriggerCreateStatementInvalid = errors.NewKind(`Invalid CREATE TRIGGER statement: %s`) 160 161 // ErrTriggerDoesNotExist is returned when a trigger does not exist. 162 ErrTriggerDoesNotExist = errors.NewKind(`trigger "%s" does not exist`) 163 164 // ErrTriggerTableInUse is returned when trigger execution calls for a table that invoked a trigger being updated by it 165 ErrTriggerTableInUse = errors.NewKind("Can't update table %s in stored function/trigger because it is already used by statement which invoked this stored function/trigger") 166 167 // ErrTriggerCannotBeDropped is returned when dropping a trigger would cause another trigger to reference a non-existent trigger. 168 ErrTriggerCannotBeDropped = errors.NewKind(`trigger "%s" cannot be dropped as it is referenced by trigger "%s"`) 169 170 // ErrStoredProceduresNotSupported is returned when attempting to create a stored procedure on a database that doesn't support them. 171 ErrStoredProceduresNotSupported = errors.NewKind(`database "%s" doesn't support stored procedures`) 172 173 // ErrVersionedStoredProceduresNotSupported is returned when attempting to retrieve a versioned stored procedure on a database that doesn't support them. 174 ErrVersionedStoredProceduresNotSupported = errors.NewKind(`database "%s" doesn't support versioned stored procedures`) 175 176 // ErrStoredProcedureAlreadyExists is returned when a stored procedure does not exist. 177 ErrStoredProcedureAlreadyExists = errors.NewKind(`stored procedure "%s" already exists`) 178 179 // ErrStoredProcedureDoesNotExist is returned when a stored procedure does not exist. 180 ErrStoredProcedureDoesNotExist = errors.NewKind(`stored procedure "%s" does not exist`) 181 182 // ErrProcedureCreateStatementInvalid is returned when a StoredProcedureDatabase returns a CREATE PROCEDURE statement that is invalid. 183 ErrProcedureCreateStatementInvalid = errors.NewKind(`Invalid CREATE PROCEDURE statement: %s`) 184 185 // ErrProcedureRecursiveCall is returned when a stored procedure has a CALL statement that refers to itself. 186 ErrProcedureRecursiveCall = errors.NewKind("recursive CALL on stored procedure `%s`") 187 188 // ErrProcedureNestedCallAsOf is returned when a stored procedure has a CALL ... AS OF statement, which is currently not allowed. 189 ErrProcedureNestedCallAsOf = errors.NewKind("CALL ... AS OF in stored procedure `%s`") 190 191 // ErrProcedureCallAsOfReadOnly is returned when a CALL ... AS OF statement attempts to modify a table. 192 ErrProcedureCallAsOfReadOnly = errors.NewKind("CALL ... AS OF converts databases to read only") 193 194 // ErrProcedureInvalidBodyStatement is returned when a stored procedure has a statement that is invalid inside of procedures. 195 ErrProcedureInvalidBodyStatement = errors.NewKind("`%s` statements are invalid inside of stored procedures") 196 197 // ErrExternalProcedureAmbiguousOverload is returned when an external stored procedure is overloaded and has two 198 // functions with the same number of parameters. 199 ErrExternalProcedureAmbiguousOverload = errors.NewKind("overloaded stored procedure `%s` may only have a single variant with `%d` parameters") 200 201 // ErrExternalProcedureNonFunction is returned when an external stored procedure is given something other than the 202 // expected function type. 203 ErrExternalProcedureNonFunction = errors.NewKind("received `%T` in place of a function for an external stored procedure") 204 205 // ErrExternalProcedureMissingContextParam is returned when an external stored procedure's first parameter is not 206 // the context. 207 ErrExternalProcedureMissingContextParam = errors.NewKind("external stored procedures require the first parameter to be the context") 208 209 // ErrExternalProcedurePointerVariadic is returned when an external stored procedure's variadic parameter has a pointer type. 210 ErrExternalProcedurePointerVariadic = errors.NewKind("an external stored procedures's variadiac parameter may not have a pointer type") 211 212 // ErrExternalProcedureReturnTypes is returned when an external stored procedure's return types are incorrect. 213 ErrExternalProcedureReturnTypes = errors.NewKind("external stored procedures must return a RowIter and error") 214 215 // ErrExternalProcedureFirstReturn is returned when an external stored procedure's first return type is incorrect. 216 ErrExternalProcedureFirstReturn = errors.NewKind("external stored procedures require the first return value to be the RowIter") 217 218 // ErrExternalProcedureSecondReturn is returned when an external stored procedure's second return type is incorrect. 219 ErrExternalProcedureSecondReturn = errors.NewKind("external stored procedures require the second return value to be the error") 220 221 // ErrExternalProcedureInvalidParamType is returned when one of an external stored procedure's parameters have an 222 // invalid type. 223 ErrExternalProcedureInvalidParamType = errors.NewKind("external stored procedures do not support parameters with type `%s`") 224 225 // ErrCallIncorrectParameterCount is returned when a CALL statement has the incorrect number of parameters. 226 ErrCallIncorrectParameterCount = errors.NewKind("`%s` expected `%d` parameters but got `%d`") 227 228 // ErrEventsNotSupported is returned when attempting to create an event on a database that doesn't support them. 229 ErrEventsNotSupported = errors.NewKind("database '%s' doesn't support events") 230 231 // ErrEventAlreadyExists is returned when an event does not exist. 232 ErrEventAlreadyExists = errors.NewKind("Event '%s' already exists") 233 234 // ErrEventDoesNotExist is returned when an event does not exist. 235 ErrEventDoesNotExist = errors.NewKind("Event '%s' does not exist") 236 237 // ErrUnknownEvent is returned when a query references an event that doesn't exist 238 ErrUnknownEvent = errors.NewKind("Unknown event '%s'") 239 240 // ErrEventCreateStatementInvalid is returned when an EventDatabase returns a CREATE EVENT statement that is invalid 241 ErrEventCreateStatementInvalid = errors.NewKind(`Invalid CREATE TRIGGER statement: %s`) 242 243 // ErrUnknownSystemVariable is returned when a query references a system variable that doesn't exist 244 ErrUnknownSystemVariable = errors.NewKind(`Unknown system variable '%s'`) 245 246 // ErrUnknownUserVariable is returned when a query references a user variable that doesn't exist 247 ErrUnknownUserVariable = errors.NewKind(`Unknown user variable '%s'`) 248 249 // ErrSystemVariableReadOnly is returned when attempting to set a value to a non-Dynamic system variable. 250 ErrSystemVariableReadOnly = errors.NewKind(`Variable '%s' is a read only variable`) 251 252 ErrSystemVariableReinitialized = errors.NewKind(`Variable '%s' was initialized more than 1x`) 253 254 // ErrSystemVariableSessionOnly is returned when attempting to set a SESSION-only variable using SET GLOBAL. 255 ErrSystemVariableSessionOnly = errors.NewKind(`Variable '%s' is a SESSION variable and can't be used with SET GLOBAL`) 256 257 // ErrSystemVariableGlobalOnly is returned when attempting to set a GLOBAL-only variable using SET SESSION. 258 ErrSystemVariableGlobalOnly = errors.NewKind(`Variable '%s' is a GLOBAL variable and should be set with SET GLOBAL`) 259 260 // ErrUserVariableNoDefault is returned when attempting to set the default value on a user variable. 261 ErrUserVariableNoDefault = errors.NewKind(`User variable '%s' does not have a default value`) 262 263 // ErrInvalidUseOfOldNew is returned when a trigger attempts to make use of OLD or NEW references when they don't exist 264 ErrInvalidUseOfOldNew = errors.NewKind("There is no %s row in on %s trigger") 265 266 // ErrInvalidUpdateOfOldRow is returned when a trigger attempts to assign to an old row's value with SET 267 ErrInvalidUpdateOfOldRow = errors.NewKind("Updating of old row is not allowed in trigger") 268 269 // ErrInvalidUpdateInAfterTrigger is returned when a trigger attempts to assign to a new row in an AFTER trigger 270 ErrInvalidUpdateInAfterTrigger = errors.NewKind("Updating of new row is not allowed in after trigger") 271 272 // ErrUnknownColumn is returned when the given column is not found in referenced table 273 ErrUnknownColumn = errors.NewKind("Unknown column '%s' in '%s'") 274 275 // ErrUnboundPreparedStatementVariable is returned when a query is executed without a binding for one its variables. 276 ErrUnboundPreparedStatementVariable = errors.NewKind(`unbound variable "%s" in query`) 277 278 // ErrUnknownPreparedStatement is returned when an unknown query is executed. 279 ErrUnknownPreparedStatement = errors.NewKind(`Unknown prepared statement handler (%s) given to EXECUTE`) 280 281 // ErrTruncateReferencedFromForeignKey is returned when a table is referenced in a foreign key and TRUNCATE is called on it. 282 ErrTruncateReferencedFromForeignKey = errors.NewKind("cannot truncate table %s as it is referenced in foreign key %s on table %s") 283 284 // ErrInvalidColTypeDefinition is returned when a column type-definition has argument violations. 285 ErrInvalidColTypeDefinition = errors.NewKind("column %s type definition is invalid: %s") 286 287 // ErrDatabaseExists is returned when CREATE DATABASE attempts to create a database that already exists. 288 ErrDatabaseExists = errors.NewKind("can't create database %s; database exists") 289 290 // ErrInvalidConstraintFunctionNotSupported is returned when a CONSTRAINT CHECK is called with an unsupported function expression. 291 ErrInvalidConstraintFunctionNotSupported = errors.NewKind("Invalid constraint expression, function not supported: %s") 292 293 // ErrInvalidConstraintSubqueryNotSupported is returned when a CONSTRAINT CHECK is called with a sub-query expression. 294 ErrInvalidConstraintSubqueryNotSupported = errors.NewKind("Invalid constraint expression, sub-queries not supported: %s") 295 296 // ErrCheckConstraintViolated is returned when a CONSTRAINT CHECK is called with a sub-query expression. 297 ErrCheckConstraintViolated = errors.NewKind("Check constraint %q violated") 298 299 // ErrCheckConstraintInvalidatedByColumnAlter is returned when an alter column statement would invalidate a check constraint. 300 ErrCheckConstraintInvalidatedByColumnAlter = errors.NewKind("can't alter column %q because it would invalidate check constraint %q") 301 302 // ErrColumnCountMismatch is returned when a view, derived table or common table expression has a declared column 303 // list with a different number of columns than the schema of the table. 304 ErrColumnCountMismatch = errors.NewKind("In definition of view, derived table or common table expression, SELECT list and column names list have different column counts") 305 306 // ErrUuidUnableToParse is returned when a UUID is unable to be parsed. 307 ErrUuidUnableToParse = errors.NewKind("unable to parse '%s' to UUID: %s") 308 309 // ErrLoadDataCannotOpen is returned when a LOAD DATA operation is unable to open the file specified. 310 ErrLoadDataCannotOpen = errors.NewKind("LOAD DATA is unable to open file: %s") 311 312 // ErrLoadDataCharacterLength is returned when a symbol is of the wrong character length for a LOAD DATA operation. 313 ErrLoadDataCharacterLength = errors.NewKind("%s must be 1 character long") 314 315 // ErrJSONObjectAggNullKey is returned when JSON_OBJECTAGG is run on a table with NULL keys 316 ErrJSONObjectAggNullKey = errors.NewKind("JSON documents may not contain NULL member names") 317 318 // ErrDeclareConditionOrderInvalid is returned when a DECLARE ... CONDITION statement is at an invalid location. 319 ErrDeclareConditionOrderInvalid = errors.NewKind("DECLARE ... CONDITION may only exist at the beginning of a BEGIN/END block") 320 321 // ErrDeclareVariableOrderInvalid is returned when a DECLARE statement, for variables, is at an invalid location. 322 ErrDeclareVariableOrderInvalid = errors.NewKind("DECLARE variables may only exist at the beginning of a BEGIN/END block") 323 324 // ErrDeclareCursorOrderInvalid is returned when a DECLARE ... CURSOR statement is at an invalid location. 325 ErrDeclareCursorOrderInvalid = errors.NewKind("DECLARE ... CURSOR may only exist at the beginning of a BEGIN/END block, following all variables and conditions") 326 327 // ErrDeclareHandlerOrderInvalid is returned when a DECLARE ... HANDLER statement is at an invalid location. 328 ErrDeclareHandlerOrderInvalid = errors.NewKind("DECLARE ... HANDLER may only exist at the beginning of a BEGIN/END block, following all variables, conditions, and cursors") 329 330 // ErrDeclareConditionNotFound is returned when SIGNAL/RESIGNAL references a non-existent DECLARE CONDITION. 331 ErrDeclareConditionNotFound = errors.NewKind("condition %s does not exist") 332 333 // ErrDeclareConditionDuplicate is returned when a DECLARE CONDITION statement with the same name was declared in the current scope. 334 ErrDeclareConditionDuplicate = errors.NewKind("duplicate condition '%s'") 335 336 // ErrDeclareVariableDuplicate is returned when a DECLARE statement reuses an existing variable name in the current scope. 337 ErrDeclareVariableDuplicate = errors.NewKind("duplicate variable '%s'") 338 339 // ErrDeclareCursorDuplicate is returned when a DECLARE ... CURSOR statement reuses an existing name in the current scope. 340 ErrDeclareCursorDuplicate = errors.NewKind("duplicate cursor '%s'") 341 342 // ErrDeclareHandlerDuplicate is returned when a DECLARE ... HANDLER statement has a duplicate in the same block. 343 ErrDeclareHandlerDuplicate = errors.NewKind("duplicate handler declared in the same block") 344 345 // ErrDeclareHandlerUndo is returned when a DECLARE ... HANDLER statement has the UNDO action, which is currently unsupported. 346 ErrDeclareHandlerUndo = errors.NewKind("DECLARE ... HANDLER does not support the UNDO action") 347 348 // ErrLoopRedefinition is returned when a loop with the same label has already been declared in the current block. 349 ErrLoopRedefinition = errors.NewKind("redefining label '%s'") 350 351 // ErrLoopLabelNotFound is returned when a control flow statement references a non-existent loop. 352 ErrLoopLabelNotFound = errors.NewKind("%s with no matching label: '%s'") 353 354 // ErrCursorNotFound is returned when a CURSOR cannot be found. 355 ErrCursorNotFound = errors.NewKind("cursor '%s' does not exist") 356 357 // ErrCursorAlreadyOpen is returned when a CURSOR is already open. 358 ErrCursorAlreadyOpen = errors.NewKind("cursor '%s' is already open") 359 360 // ErrCursorNotOpen is returned when a CURSOR has not yet been opened. 361 ErrCursorNotOpen = errors.NewKind("cursor '%s' is not open") 362 363 // ErrFetchIncorrectCount is returned when a FETCH does not use the correct number of variables. 364 ErrFetchIncorrectCount = errors.NewKind("incorrect number of FETCH variables") 365 366 // ErrSignalOnlySqlState is returned when SIGNAL/RESIGNAL references a DECLARE CONDITION for a MySQL error code. 367 ErrSignalOnlySqlState = errors.NewKind("SIGNAL/RESIGNAL can only use a condition defined with SQLSTATE") 368 369 // ErrExpectedSingleRow is returned when a subquery executed in normal queries or aggregation function returns 370 // more than 1 row without an attached IN clause. 371 ErrExpectedSingleRow = errors.NewKind("the subquery returned more than 1 row") 372 373 // ErrUnknownConstraint is returned when a DROP CONSTRAINT statement refers to a constraint that doesn't exist 374 ErrUnknownConstraint = errors.NewKind("Constraint %q does not exist") 375 376 // ErrInsertIntoNonNullableDefaultNullColumn is returned when an INSERT excludes a field which is non-nullable and has no default/autoincrement. 377 ErrInsertIntoNonNullableDefaultNullColumn = errors.NewKind("Field '%s' doesn't have a default value") 378 379 // ErrAlterTableNotSupported is thrown when the table doesn't support ALTER TABLE statements 380 ErrAlterTableNotSupported = errors.NewKind("table %s cannot be altered") 381 382 // ErrAlterTableCollationNotSupported is thrown when the table doesn't support ALTER TABLE COLLATE statements 383 ErrAlterTableCollationNotSupported = errors.NewKind("table %s cannot have its collation altered") 384 385 // ErrCollationNotSupportedOnUniqueTextIndex is thrown when a unique index is created on a TEXT column, with no 386 // prefix length specified, and the collation is case-insensitive or accent-insensitive, meaning we can't 387 // reliably use a content-hashed field to detect uniqueness. 388 ErrCollationNotSupportedOnUniqueTextIndex = errors.NewKind("unable to create a unique index on TEXT columns without " + 389 "a prefix length specified when using a case-insensitive or accent-insensitive collation") 390 391 // ErrPartitionNotFound is thrown when a partition key on a table is not found 392 ErrPartitionNotFound = errors.NewKind("partition not found %q") 393 394 // ErrInsertIntoNonNullableProvidedNull is called when a null value is inserted into a non-nullable column 395 ErrInsertIntoNonNullableProvidedNull = errors.NewKind("column name '%v' is non-nullable but attempted to set a value of null") 396 397 // ErrForeignKeyChildViolation is called when a rows is added but there is no parent row, and a foreign key constraint fails. Add the parent row first. 398 ErrForeignKeyChildViolation = errors.NewKind("cannot add or update a child row - Foreign key violation on fk: `%s`, table: `%s`, referenced table: `%s`, key: `%s`") 399 400 // ErrForeignKeyParentViolation is called when a parent row that is deleted has children, and a foreign key constraint fails. Delete the children first. 401 ErrForeignKeyParentViolation = errors.NewKind("cannot delete or update a parent row - Foreign key violation on fk: `%s`, table: `%s`, referenced table: `%s`, key: `%s`") 402 403 // ErrForeignKeyColumnCountMismatch is called when the declared column and referenced column counts do not match. 404 ErrForeignKeyColumnCountMismatch = errors.NewKind("the foreign key must reference an equivalent number of columns") 405 406 // ErrForeignKeyColumnTypeMismatch is returned when the declared column's type and referenced column's type do not match. 407 ErrForeignKeyColumnTypeMismatch = errors.NewKind("column type mismatch on `%s` and `%s`") 408 409 // ErrForeignKeyNotResolved is called when an add or update is attempted on a foreign key that has not been resolved yet. 410 ErrForeignKeyNotResolved = errors.NewKind("cannot add or update a child row: a foreign key constraint fails (`%s`.`%s`, CONSTRAINT `%s` FOREIGN KEY (`%s`) REFERENCES `%s` (`%s`))") 411 412 // ErrNoForeignKeySupport is returned when the table does not support FOREIGN KEY operations. 413 ErrNoForeignKeySupport = errors.NewKind("the table does not support foreign key operations: %s") 414 415 // ErrForeignKeyMissingColumns is returned when an ALTER TABLE ADD FOREIGN KEY statement does not provide any columns 416 ErrForeignKeyMissingColumns = errors.NewKind("cannot create a foreign key without columns") 417 418 // ErrForeignKeyDropColumn is returned when attempting to drop a column used in a foreign key 419 ErrForeignKeyDropColumn = errors.NewKind("cannot drop column `%s` as it is used in foreign key `%s`") 420 421 // ErrForeignKeyDropTable is returned when attempting to drop a table used in a foreign key 422 ErrForeignKeyDropTable = errors.NewKind("cannot drop table `%s` as it is referenced in foreign key `%s`") 423 424 // ErrForeignKeyDropIndex is returned when attempting to drop an index used in a foreign key when there are no other 425 // indexes which may be used in its place. 426 ErrForeignKeyDropIndex = errors.NewKind("cannot drop index: `%s` is used by foreign key `%s`") 427 428 // ErrForeignKeyDuplicateName is returned when a foreign key already exists with the given name. 429 ErrForeignKeyDuplicateName = errors.NewKind("duplicate foreign key constraint name `%s`") 430 431 // ErrAddForeignKeyDuplicateColumn is returned when an ALTER TABLE ADD FOREIGN KEY statement has the same column multiple times 432 ErrAddForeignKeyDuplicateColumn = errors.NewKind("cannot have duplicates of columns in a foreign key: `%v`") 433 434 // ErrTemporaryTablesForeignKeySupport is returned when a user tries to create a temporary table with a foreign key 435 ErrTemporaryTablesForeignKeySupport = errors.NewKind("temporary tables do not support foreign keys") 436 437 // ErrForeignKeyNotFound is returned when a foreign key was not found. 438 ErrForeignKeyNotFound = errors.NewKind("foreign key `%s` was not found on the table `%s`") 439 440 // ErrForeignKeySetDefault is returned when attempting to set a referential action as SET DEFAULT. 441 ErrForeignKeySetDefault = errors.NewKind(`"SET DEFAULT" is not supported`) 442 443 // ErrForeignKeySetNullNonNullable is returned when attempting to set a referential action as SET NULL when the 444 // column is non-nullable. 445 ErrForeignKeySetNullNonNullable = errors.NewKind("cannot use SET NULL as column `%s` is non-nullable") 446 447 // ErrForeignKeyTypeChangeSetNull is returned when attempting to change a column's type to disallow NULL values when 448 // a foreign key referential action is SET NULL. 449 ErrForeignKeyTypeChangeSetNull = errors.NewKind("column `%s` must allow NULL values as foreign key `%s` has SET NULL") 450 451 // ErrForeignKeyMissingReferenceIndex is returned when the referenced columns in a foreign key do not have an index. 452 ErrForeignKeyMissingReferenceIndex = errors.NewKind("missing index for foreign key `%s` on the referenced table `%s`") 453 454 // ErrForeignKeyTextBlob is returned when a TEXT or BLOB column is used in a foreign key, which are not valid types. 455 ErrForeignKeyTextBlob = errors.NewKind("TEXT/BLOB are not valid types for foreign keys") 456 457 // ErrForeignKeyTypeChange is returned when attempting to change the type of some column used in a foreign key. 458 ErrForeignKeyTypeChange = errors.NewKind("unable to change type of column `%s` as it is used by foreign keys") 459 460 // ErrForeignKeyDepthLimit is returned when the CASCADE depth limit has been reached. 461 ErrForeignKeyDepthLimit = errors.NewKind("Foreign key cascade delete/update exceeds max depth of 15.") 462 463 // ErrDuplicateEntry is returns when a duplicate entry is placed on an index such as a UNIQUE or a Primary Key. 464 ErrDuplicateEntry = errors.NewKind("Duplicate entry for key '%s'") 465 466 // ErrDuplicateColumn is returned when a table has two columns with the same name. 467 ErrDuplicateColumn = errors.NewKind("duplicate column name: `%s`") 468 469 // ErrInvalidIdentifier is returned when an identifier is invalid 470 ErrInvalidIdentifier = errors.NewKind("invalid identifier: `%s`") 471 472 // ErrInvalidArgument is returned when an argument to a function is invalid. 473 ErrInvalidArgument = errors.NewKind("Invalid argument to %s") 474 475 // ErrInvalidArgumentType is thrown when a function receives invalid argument types 476 ErrInvalidArgumentType = errors.NewKind("function '%s' received invalid argument types") 477 478 // ErrInvalidArgumentDetails is returned when the argument is invalid with details of a specific function 479 ErrInvalidArgumentDetails = errors.NewKind("Invalid argument to %s: %s") 480 481 // ErrSavepointDoesNotExist is returned when a RELEASE SAVEPOINT or ROLLBACK TO SAVEPOINT statement references a 482 // non-existent savepoint identifier 483 ErrSavepointDoesNotExist = errors.NewKind("SAVEPOINT %s does not exist") 484 485 // ErrTemporaryTableNotSupported is thrown when an integrator attempts to create a temporary tables without temporary table 486 // support. 487 ErrTemporaryTableNotSupported = errors.NewKind("database does not support temporary tables") 488 489 // ErrInvalidSyntax is returned for syntax errors that aren't picked up by the parser, e.g. the wrong type of 490 // expression used in part of statement. 491 ErrInvalidSyntax = errors.NewKind("Invalid syntax: %s") 492 493 // ErrTableCopyingNotSupported is returned when a table invokes the TableCopierDatabase interface's 494 // CopyTableData method without supporting the interface 495 ErrTableCopyingNotSupported = errors.NewKind("error: Table copying not supported") 496 497 // ErrMultiplePrimaryKeysDefined is returned when a table invokes CreatePrimaryKey with a primary key already 498 // defined. 499 ErrMultiplePrimaryKeysDefined = errors.NewKind("error: Multiple primary keys defined") 500 501 // ErrWrongAutoKey is returned when a table invokes DropPrimaryKey without first removing the auto increment property 502 // (if it exists) on it. 503 ErrWrongAutoKey = errors.NewKind("error: incorrect table definition: there can be only one auto column and it must be defined as a key") 504 505 // ErrKeyColumnDoesNotExist is returned when a table invoked CreatePrimaryKey with a non-existent column. 506 ErrKeyColumnDoesNotExist = errors.NewKind("error: key column '%s' doesn't exist in table") 507 508 // ErrCantDropFieldOrKey is returned when a table invokes DropPrimaryKey on a keyless table. 509 ErrCantDropFieldOrKey = errors.NewKind("error: can't drop '%s'; check that column/key exists") 510 511 // ErrCantDropIndex is return when a table can't drop an index due to a foreign key relationship. 512 ErrCantDropIndex = errors.NewKind("error: can't drop index '%s': needed in foreign key constraint %s") 513 514 // ErrImmutableDatabaseProvider is returned when attempting to edit an immutable database databaseProvider. 515 ErrImmutableDatabaseProvider = errors.NewKind("error: can't modify database databaseProvider") 516 517 // ErrInvalidValue is returned when a given value does not match what is expected. 518 ErrInvalidValue = errors.NewKind(`error: '%v' is not a valid value for '%v'`) 519 520 // ErrInvalidValueType is returned when a given value's type does not match what is expected. 521 ErrInvalidValueType = errors.NewKind(`error: '%T' is not a valid value type for '%v'`) 522 523 // ErrFunctionNotFound is thrown when a function is not found 524 ErrFunctionNotFound = errors.NewKind("function: '%s' not found") 525 526 // ErrConflictingExternalQuery is thrown when a scope's parent has a conflicting sort or limit node 527 ErrConflictingExternalQuery = errors.NewKind("found external scope with conflicting ORDER BY/LIMIT") 528 529 // ErrTableFunctionNotFound is thrown when a table function is not found 530 ErrTableFunctionNotFound = errors.NewKind("table function: '%s' not found") 531 532 // ErrNonAggregatedColumnWithoutGroupBy is thrown when an aggregate function is used with the implicit, all-rows 533 // grouping and another projected expression contains a non-aggregated column. 534 // MySQL error code: 1140, SQL state: 42000 535 ErrNonAggregatedColumnWithoutGroupBy = errors.NewKind("in aggregated query without GROUP BY, expression #%d of SELECT list contains nonaggregated column '%s'; " + 536 "this is incompatible with sql_mode=only_full_group_by") 537 538 // ErrInvalidArgumentNumber is returned when the number of arguments to call a 539 // function is different from the function arity. 540 ErrInvalidArgumentNumber = errors.NewKind("function '%s' expected %v arguments, %v received") 541 542 // ErrDatabaseNotFound is thrown when a database is not found 543 ErrDatabaseNotFound = errors.NewKind("database not found: %s") 544 545 // ErrNoDatabaseSelected is thrown when a database is not selected and the query requires one 546 ErrNoDatabaseSelected = errors.NewKind("no database selected") 547 548 // ErrAsOfNotSupported is thrown when an AS OF query is run on a database that can't support it 549 ErrAsOfNotSupported = errors.NewKind("AS OF not supported for database %s") 550 551 // ErrIncompatibleAsOf is thrown when an AS OF clause is used in an incompatible manner, such as when using an AS OF 552 // expression with a view when the view definition has its own AS OF expressions. 553 ErrIncompatibleAsOf = errors.NewKind("incompatible use of AS OF: %s") 554 555 // ErrPidAlreadyUsed is returned when the pid is already registered. 556 ErrPidAlreadyUsed = errors.NewKind("pid %d is already in use") 557 558 // ErrInvalidOperandColumns is returned when the columns in the left 559 // operand and the elements of the right operand don't match. Also 560 // returned for invalid number of columns in projections, filters, 561 // joins, etc. 562 ErrInvalidOperandColumns = errors.NewKind("operand should have %d columns, but has %d") 563 564 // ErrReadOnlyTransaction is returned when a write query is executed in a READ ONLY transaction. 565 ErrReadOnlyTransaction = errors.NewKind("cannot execute statement in a READ ONLY transaction") 566 567 // ErrLockDeadlock is the go-mysql-server equivalent of ER_LOCK_DEADLOCK. Transactions throwing this error 568 // are automatically rolled back. Clients receiving this error must retry the transaction. 569 ErrLockDeadlock = errors.NewKind("serialization failure: %s, try restarting transaction.") 570 571 // ErrViewsNotSupported is returned when attempting to access a view on a database that doesn't support them. 572 ErrViewsNotSupported = errors.NewKind("database '%s' doesn't support views") 573 574 // ErrExpectedTableFoundView is returned when attempting to rename a view using ALTER TABLE statement. 575 ErrExpectedTableFoundView = errors.NewKind("expected a table and found view: '%s' ") 576 577 // ErrExistingView is returned when a CREATE VIEW statement uses a name that already exists 578 ErrExistingView = errors.NewKind("the view %s.%s already exists") 579 580 // ErrViewDoesNotExist is returned when a DROP VIEW statement drops a view that does not exist 581 ErrViewDoesNotExist = errors.NewKind("the view %s.%s does not exist") 582 583 // ErrSessionDoesNotSupportPersistence is thrown when a feature is not already supported 584 ErrSessionDoesNotSupportPersistence = errors.NewKind("session does not support persistence") 585 586 // ErrInvalidGISData is thrown when a "ST_<spatial_type>FromText" function receives a malformed string 587 ErrInvalidGISData = errors.NewKind("invalid GIS data provided to function %s") 588 589 // ErrIllegalGISValue is thrown when a spatial type constructor receives a non-geometric when one should be provided 590 ErrIllegalGISValue = errors.NewKind("illegal non geometric '%v' value found during parsing") 591 592 // ErrDiffSRIDs is thrown when comparing two spatial types that have different SRIDs when they should be the same 593 ErrDiffSRIDs = errors.NewKind("binary geometry function %s given two geometries of different srids: %v and %v, which should have been identical") 594 595 // ErrUnsupportedSRID is thrown for spatial functions over unsupported SRIDs 596 ErrUnsupportedSRID = errors.NewKind("SRID %v has not been implemented for geographic spatial reference systems.") 597 598 // ErrSRIDOnNonGeomCol is thrown when attempting to define SRID over a non-geometry column 599 ErrSRIDOnNonGeomCol = errors.NewKind("incorrect usage of SRID and non-geometry column") 600 601 // ErrTooManyKeyParts is thrown when creating an index with too many columns 602 ErrTooManyKeyParts = errors.NewKind("too many key parts specified; max %d parts allowed") 603 604 // ErrNullableSpatialIdx is thrown when creating a SPATIAL index with a nullable column 605 ErrNullableSpatialIdx = errors.NewKind("All parts of a SPATIAL index must be NOT NULL") 606 607 // ErrBadSpatialIdxCol is thrown when attempting to define a SPATIAL index over a non-geometry column 608 ErrBadSpatialIdxCol = errors.NewKind("a SPATIAL index may only contain a geometrical type column") 609 610 // ErrNoSRID is thrown when attempting to create a Geometry with a non-existent SRID 611 ErrNoSRID = errors.NewKind("There's no spatial reference with SRID %d") 612 613 // ErrInvalidSRID is thrown when attempting to create a Geometry with an invalid SRID 614 ErrInvalidSRID = errors.NewKind("SRID value is out of range in %s") 615 616 // ErrSpatialRefSysAlreadyExists is thrown when attempting to create a spatial reference system with an existing SRID 617 ErrSpatialRefSysAlreadyExists = errors.NewKind("There is already a spatial reference system with SRID %v") 618 619 // ErrUnsupportedGISTypeForSpatialFunc is a temporary error because geometry is hard 620 // TODO: remove this error when all types are full supported by spatial type functions 621 ErrUnsupportedGISTypeForSpatialFunc = errors.NewKind("unsupported spatial type: %s for function %s") 622 623 // ErrUnsupportedGISType is thrown when attempting to convert an unsupported geospatial value to a geometry struct 624 ErrUnsupportedGISType = errors.NewKind("unsupported geospatial type: %s from value: 0x%s") 625 626 // ErrUnsupportedSyntax is returned when syntax that parses correctly is not supported 627 ErrUnsupportedSyntax = errors.NewKind("unsupported syntax: %s") 628 629 // ErrInvalidSQLValType is returned when a SQL value is of the incorrect type during parsing 630 ErrInvalidSQLValType = errors.NewKind("invalid SQLVal of type: %d") 631 632 // ErrUnknownIndexColumn is returned when a column in an index is not in the table 633 ErrUnknownIndexColumn = errors.NewKind("unknown column: '%s' in index '%s'") 634 635 // ErrInvalidAutoIncCols is returned when an auto_increment column cannot be applied 636 ErrInvalidAutoIncCols = errors.NewKind("there can be only one auto_increment column and it must be defined as a key") 637 638 // ErrUnknownConstraintDefinition is returned when an unknown constraint type is used 639 ErrUnknownConstraintDefinition = errors.NewKind("unknown constraint definition: %s, %T") 640 641 // ErrInvalidCheckConstraint is returned when a check constraint is defined incorrectly 642 ErrInvalidCheckConstraint = errors.NewKind("invalid constraint definition: %s") 643 644 // ErrUserCreationFailure is returned when attempting to create a user and it fails for any reason. 645 ErrUserCreationFailure = errors.NewKind("Operation CREATE USER failed for %s") 646 647 // ErrUserAlterFailure is returned when attempting to alter a user and it fails for any reason. 648 ErrUserAlterFailure = errors.NewKind("Operation ALTER USER failed for %s") 649 650 // ErrRoleCreationFailure is returned when attempting to create a role and it fails for any reason. 651 ErrRoleCreationFailure = errors.NewKind("Operation CREATE ROLE failed for %s") 652 653 // ErrUserDeletionFailure is returned when attempting to create a user and it fails for any reason. 654 ErrUserDeletionFailure = errors.NewKind("Operation DROP USER failed for %s") 655 656 // ErrRoleDeletionFailure is returned when attempting to create a role and it fails for any reason. 657 ErrRoleDeletionFailure = errors.NewKind("Operation DROP ROLE failed for %s") 658 659 // ErrDatabaseAccessDeniedForUser is returned when attempting to access a database that the user does not have 660 // permission for, regardless of whether that database actually exists. 661 ErrDatabaseAccessDeniedForUser = errors.NewKind("Access denied for user %s to database '%s'") 662 663 // ErrTableAccessDeniedForUser is returned when attempting to access a table that the user does not have permission 664 // for, regardless of whether that table actually exists. 665 ErrTableAccessDeniedForUser = errors.NewKind("Access denied for user %s to table '%s'") 666 667 // ErrPrivilegeCheckFailed is returned when a user does not have the correct privileges to perform an operation. 668 ErrPrivilegeCheckFailed = errors.NewKind("command denied to user %s") 669 670 // ErrGrantUserDoesNotExist is returned when a user does not exist when attempting to grant them privileges. 671 ErrGrantUserDoesNotExist = errors.NewKind("You are not allowed to create a user with GRANT") 672 673 // ErrRevokeUserDoesNotExist is returned when a user does not exist when attempting to revoke privileges from them. 674 ErrRevokeUserDoesNotExist = errors.NewKind("There is no such grant defined for user '%s' on host '%s'") 675 676 // ErrGrantRevokeRoleDoesNotExist is returned when a user or role does not exist when attempting to grant or revoke roles. 677 ErrGrantRevokeRoleDoesNotExist = errors.NewKind("Unknown authorization ID %s") 678 679 // ErrShowGrantsUserDoesNotExist is returned when a user does not exist when attempting to show their grants. 680 ErrShowGrantsUserDoesNotExist = errors.NewKind("There is no such grant defined for user '%s' on host '%s'") 681 682 // ErrRecursiveCTEMissingUnion is returned when a recursive CTE is not a UNION or UNION ALL node. 683 ErrRecursiveCTEMissingUnion = errors.NewKind("Recursive Common Table Expression '%s' should contain a UNION") 684 685 // ErrRecursiveCTENotUnion is returned when an INTERSECT or EXCEPT includes a Recursive CTE. 686 ErrRecursiveCTENotUnion = errors.NewKind("Recursive table reference in EXCEPT or INTERSECT operand is not allowed") 687 688 // ErrCteRecursionLimitExceeded is returned when a recursive CTE's execution stack depth exceeds the static limit. 689 ErrCteRecursionLimitExceeded = errors.NewKind("WITH RECURSIVE iteration limit exceeded") 690 691 // ErrGrantRevokeIllegalPrivilege is returned when a GRANT or REVOKE statement is malformed, or attempts to use privilege incorrectly. 692 ErrGrantRevokeIllegalPrivilege = errors.NewKind("Illegal GRANT/REVOKE command") 693 694 // ErrGrantRevokeIllegalPrivilegeWithMessage is returned when a GRANT or REVOKE statement is malformed, or attempts 695 // to use privilege incorrectly and an additional message needs to be provided to the user. 696 ErrGrantRevokeIllegalPrivilegeWithMessage = errors.NewKind("Illegal GRANT/REVOKE command: %s") 697 698 // ErrInvalidWindowInheritance is returned when a window and its dependency contains conflicting partitioning, ordering, or framing clauses 699 ErrInvalidWindowInheritance = errors.NewKind("window '%s' cannot inherit '%s' since %s") 700 701 // ErrCircularWindowInheritance is returned when a WINDOW clause has a circular dependency 702 ErrCircularWindowInheritance = errors.NewKind("there is a circularity in the window dependency graph") 703 704 // ErrCannotCopyWindowFrame is returned when we inherit a window frame with a frame clause (replacement without parenthesis is OK) 705 ErrCannotCopyWindowFrame = errors.NewKind("cannot copy window '%s' because it has a frame clause") 706 707 // ErrUnknownWindowName is returned when an over by clause references an unknown window definition 708 ErrUnknownWindowName = errors.NewKind("named window not found: '%s'") 709 710 // ErrUnexpectedNilRow is returned when an invalid operation is applied to an empty row 711 ErrUnexpectedNilRow = errors.NewKind("unexpected nil row") 712 713 // ErrMoreThanOneRow is returned when the result consists of multiple rows, when only one row is expected 714 ErrMoreThanOneRow = errors.NewKind("Result consisted of more than one row") 715 716 // ErrColumnNumberDoesNotMatch is returned when the number of columns in result does not match expected number of variables 717 ErrColumnNumberDoesNotMatch = errors.NewKind("The used SELECT statements have a different number of columns") 718 719 // ErrUnsupportedJoinFactorCount is returned for a query with more commutable join tables than we support 720 ErrUnsupportedJoinFactorCount = errors.NewKind("unsupported join factor count: expected fewer than %d tables, found %d") 721 722 // ErrSecureFilePriv is returned when an outfile/dumpfile path is invalid or not under the secure-file-priv directory 723 ErrSecureFilePriv = errors.NewKind("The MySQL server is running with the --secure-file-priv option so it cannot execute this statement") 724 725 // ErrFileExists is returned when a file already exists 726 ErrFileExists = errors.NewKind("File '%s' already exists") 727 728 // ErrUnexpectedSeparator is returned when an invalid separator is used 729 ErrUnexpectedSeparator = errors.NewKind("Field separator argument is not what is expected; check the manual") 730 731 // ErrNotMatchingSRID is returned for SRID values not matching 732 ErrNotMatchingSRID = errors.NewKind("The SRID of the geometry is %v, but the SRID of the column is %v. Consider changing the SRID of the geometry or the SRID property of the column.") 733 734 // ErrNotMatchingSRIDWithColName is returned for error of SRID values not matching with column name detail 735 ErrNotMatchingSRIDWithColName = errors.NewKind("The SRID of the geometry does not match the SRID of the column '%s'. %v") 736 737 // ErrSpatialTypeConversion is returned when one spatial type cannot be converted to the other spatial type 738 ErrSpatialTypeConversion = errors.NewKind("Cannot get geometry object from data you sent to the GEOMETRY field") 739 740 // ErrUnsupportedIndexPrefix is returned for an index on a string column with a prefix 741 ErrUnsupportedIndexPrefix = errors.NewKind("prefix index on string column '%s' unsupported") 742 743 // ErrInvalidIndexPrefix is returned for an index prefix on a non-string column, or the prefix is longer than string itself, or just unsupported 744 ErrInvalidIndexPrefix = errors.NewKind("incorrect prefix key '%s'; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys") 745 746 // ErrInvalidBlobTextKey is returned for an index on a blob or text column with no key length specified 747 ErrInvalidBlobTextKey = errors.NewKind("blob/text column '%s' used in key specification without a key length") 748 749 // ErrKeyTooLong is returned for an index on a blob or text column that is longer than 3072 bytes 750 ErrKeyTooLong = errors.NewKind("specified key was too long; max key length is 3072 bytes") 751 752 // ErrKeyZero is returned for an index on a blob or text column that is 0 in length 753 ErrKeyZero = errors.NewKind("key part '%s' length cannot be 0") 754 755 // ErrDatabaseWriteLocked is returned when a database is locked in read-only mode to avoid 756 // conflicts with an active server 757 ErrDatabaseWriteLocked = errors.NewKind("database is locked to writes") 758 759 // ErrCollationMalformedString is returned when a malformed string is encountered during a collation-related operation. 760 ErrCollationMalformedString = errors.NewKind("malformed string encountered while %s") 761 762 // ErrCollatedExprWrongType is returned when the wrong type is given to a CollatedExpression. 763 ErrCollatedExprWrongType = errors.NewKind("wrong type in collated expression") 764 765 // ErrCollationInvalidForCharSet is returned when the wrong collation is given for the character set when parsing. 766 ErrCollationInvalidForCharSet = errors.NewKind("COLLATION '%s' is not valid for CHARACTER SET '%s'") 767 768 // ErrCollationUnknown is returned when the collation is not a recognized MySQL collation. 769 ErrCollationUnknown = errors.NewKind("Unknown collation: %v") 770 771 // ErrCollationNotYetImplementedTemp is returned when the collation is valid but has not yet been implemented. 772 // This error is temporary, and will be removed once all collations have been added. 773 ErrCollationNotYetImplementedTemp = errors.NewKind("The collation `%s` has not yet been implemented, " + 774 "please create an issue at https://github.com/dolthub/go-mysql-server/issues/new and the DoltHub developers will implement it") 775 776 // ErrCollationIllegalMix is returned when two different collations are used in a scenario where they are not compatible. 777 ErrCollationIllegalMix = errors.NewKind("Illegal mix of collations (%v) and (%v)") 778 779 // ErrCharSetIntroducer is returned when a character set introducer is not attached to a string 780 ErrCharSetIntroducer = errors.NewKind("CHARACTER SET introducer must be attached to a string") 781 782 // ErrCharSetInvalidString is returned when an invalid string is given for a character set. 783 ErrCharSetInvalidString = errors.NewKind("invalid string for character set `%s`: \"%s\"") 784 785 // ErrCharSetFailedToEncode is returned when a character set fails encoding 786 ErrCharSetFailedToEncode = errors.NewKind("failed to encode: `%s`, valid string: `%v`, snippet: `%s`") 787 788 // ErrCharSetUnknown is returned when the character set is not a recognized MySQL character set 789 ErrCharSetUnknown = errors.NewKind("Unknown character set: %v") 790 791 // ErrCharSetNotYetImplementedTemp is returned when the character set is valid but has not yet been implemented. 792 // This error is temporary, and will be removed once all character sets have been added. 793 ErrCharSetNotYetImplementedTemp = errors.NewKind("The character set `%s` has not yet been implemented, " + 794 "please create an issue at https://github.com/dolthub/go-mysql-server/issues/new and the DoltHub developers will implement it") 795 796 // ErrNoTablesUsed is returned when there is no table provided or dual table is defined with column access. 797 ErrNoTablesUsed = errors.NewKind("No tables used") 798 799 // ErrInvalidJson is returned when a JSON string doesn't represent valid JSON. 800 ErrInvalidJson = errors.NewKind("Invalid JSON text: %s") 801 802 // ErrNoAutoIncrementCol is returned when there is no auto increment column defined on a table. 803 ErrNoAutoIncrementCol = fmt.Errorf("this table has no AUTO_INCREMENT columns") 804 805 // ErrValueOutOfRange is returned when a value is out of range for a type. 806 ErrValueOutOfRange = errors.NewKind("%v out of range for %v") 807 808 ErrConvertingToSet = errors.NewKind("value %v is not valid for this set") 809 ErrDuplicateEntrySet = errors.NewKind("duplicate entry: %v") 810 ErrInvalidSetValue = errors.NewKind("value %v was not found in the set") 811 ErrTooLargeForSet = errors.NewKind(`value "%v" is too large for this set`) 812 ErrNotPoint = errors.NewKind("value of type %T is not a point") 813 ErrNotLineString = errors.NewKind("value of type %T is not a linestring") 814 815 // ErrMergeJoinExpectsComparerFilters is returned when we attempt to build a merge join with an invalid filter. 816 ErrMergeJoinExpectsComparerFilters = errors.NewKind("merge join expects expression.Comparer filters, found: %T") 817 818 // ErrNoJoinFilters is returned when we attempt to build a filtered join without filters 819 ErrNoJoinFilters = errors.NewKind("join expected non-nil filters") 820 821 // ErrDroppedJoinFilters is returned when we removed filters from a join, but failed to re-insert them 822 ErrDroppedJoinFilters = errors.NewKind("dropped filters from join, but failed to re-insert them") 823 824 // ErrInvalidIndexName is called when we try to create an index with an unusable name. 825 ErrInvalidIndexName = errors.NewKind("invalid index name '%s'") 826 827 // ErrStarUnsupported is called for * expressions seen outside: raw projections, count(*), and arrayagg(*) 828 ErrStarUnsupported = errors.NewKind( 829 "a '*' is in a context where it is not allowed.", 830 ) 831 832 // ErrAggregationUnsupported is returned when the analyzer has failed 833 // to push down an Aggregation in an expression to a GroupBy node. 834 ErrAggregationUnsupported = errors.NewKind( 835 "an aggregation remained in the expression '%s' after analysis, outside of a node capable of evaluating it; this query is currently unsupported.", 836 ) 837 838 ErrWindowUnsupported = errors.NewKind( 839 "a window function '%s' is in a context where it cannot be evaluated.", 840 ) 841 842 // ErrFullTextNotSupported is returned when a table does not support the creation of Full-Text indexes. 843 ErrFullTextNotSupported = errors.NewKind("table does not support FULLTEXT indexes") 844 845 // ErrFullTextDatabaseNotSupported is returned when a database does not support the creation of Full-Text indexes. 846 ErrFullTextDatabaseNotSupported = errors.NewKind("database does not support FULLTEXT indexes") 847 848 // ErrIncompleteFullTextIntegration is returned when some portions of Full-Text are implemented but not all of them 849 ErrIncompleteFullTextIntegration = errors.NewKind("proper Full-Text support requires all interfaces to be implemented") 850 851 // ErrNoFullTextIndexFound is returned when the relevant Full-Text index cannot be found. 852 ErrNoFullTextIndexFound = errors.NewKind("no matching Full-Text index found on table `%s`") 853 854 // ErrFullTextMatchAgainstNotColumns is returned when the provided MATCH(...) columns are not column names. 855 ErrFullTextMatchAgainstNotColumns = errors.NewKind("match columns must be column names") 856 857 // ErrFullTextMatchAgainstSameTable is returned when the provided MATCH(...) columns belong to different tables. 858 ErrFullTextMatchAgainstSameTable = errors.NewKind("match columns must refer to the same table") 859 860 // ErrFullTextDifferentCollations is returned when creating a Full-Text index on columns that have different collations. 861 ErrFullTextDifferentCollations = errors.NewKind("Full-Text index columns must have the same collation") 862 863 // ErrFullTextMissingColumn is returned when a Full-Text column cannot be found. 864 ErrFullTextMissingColumn = errors.NewKind("Full-Text index could not find the column `%s`") 865 866 // ErrFullTextDuplicateColumn is returned when a Full-Text index declares the same column multiple times. 867 ErrFullTextDuplicateColumn = errors.NewKind("cannot have duplicate columns in a Full-Text index: `%s`") 868 869 // ErrFullTextInvalidColumnType is returned when a Full-Text index is declared on a non-text column. 870 ErrFullTextInvalidColumnType = errors.NewKind("all Full-Text columns must be declared on a non-binary text type") 871 872 // ErrGeneratedColumnValue is returned when a value is provided for a generated column 873 ErrGeneratedColumnValue = errors.NewKind("The value specified for generated column %q in table %q is not allowed.") 874 875 // ErrVirtualColumnPrimaryKey is returned when a virtual column is defined as a primary key 876 ErrVirtualColumnPrimaryKey = errors.NewKind("Defining a virtual generated column as primary key is not supported") 877 878 // ErrGeneratedColumnWithDefault is returned when a column specifies both a default and a generated value 879 ErrGeneratedColumnWithDefault = errors.NewKind("Incorrect usage of DEFAULT and generated column") 880 881 ErrInvalidOnUpdate = errors.NewKind("Invalid ON UPDATE clause for '%s' column") 882 883 ErrInsertIntoMismatchValueCount = errors.NewKind("number of values does not match number of columns provided") 884 885 ErrInvalidTypeForLimit = errors.NewKind("invalid limit. expected %T, found %T") 886 887 ErrColumnSpecifiedTwice = errors.NewKind("column '%v' specified twice") 888 ) 889 890 // CastSQLError returns a *mysql.SQLError with the error code and in some cases, also a SQL state, populated for the 891 // specified error object. Using this method enables Vitess to return an error code, instead of just "unknown error". 892 // Many tools (e.g. ORMs, SQL workbenches) rely on this error metadata to work correctly. If the specified error is nil, 893 // nil will be returned. If the error is already of type *mysql.SQLError, the error will be returned as is. 894 func CastSQLError(err error) *mysql.SQLError { 895 if err == nil { 896 return nil 897 } 898 if mysqlErr, ok := err.(*mysql.SQLError); ok { 899 return mysqlErr 900 } 901 902 var code int 903 var sqlState string = "" 904 905 if w, ok := err.(WrappedInsertError); ok { 906 return CastSQLError(w.Cause) 907 } 908 909 if wm, ok := err.(WrappedTypeConversionError); ok { 910 return CastSQLError(wm.Err) 911 } 912 913 switch { 914 case ErrTableNotFound.Is(err): 915 code = mysql.ERNoSuchTable 916 case ErrDatabaseExists.Is(err): 917 code = mysql.ERDbCreateExists 918 case ErrExpectedSingleRow.Is(err): 919 code = mysql.ERSubqueryNo1Row 920 case ErrInvalidOperandColumns.Is(err): 921 code = mysql.EROperandColumns 922 case ErrInsertIntoNonNullableProvidedNull.Is(err): 923 code = mysql.ERBadNullError 924 case ErrNonAggregatedColumnWithoutGroupBy.Is(err): 925 code = mysql.ERMixOfGroupFuncAndFields 926 case ErrPrimaryKeyViolation.Is(err): 927 code = mysql.ERDupEntry 928 case ErrUniqueKeyViolation.Is(err): 929 code = mysql.ERDupEntry 930 case ErrPartitionNotFound.Is(err): 931 code = 1526 // TODO: Needs to be added to vitess 932 case ErrForeignKeyChildViolation.Is(err): 933 code = mysql.ErNoReferencedRow2 // test with mysql returns 1452 vs 1216 934 case ErrForeignKeyParentViolation.Is(err): 935 code = mysql.ERRowIsReferenced2 // test with mysql returns 1451 vs 1215 936 case ErrDuplicateEntry.Is(err): 937 code = mysql.ERDupEntry 938 case ErrInvalidJSONText.Is(err): 939 code = 3141 // TODO: Needs to be added to vitess 940 case ErrMultiplePrimaryKeysDefined.Is(err): 941 code = mysql.ERMultiplePriKey 942 case ErrWrongAutoKey.Is(err): 943 code = mysql.ERWrongAutoKey 944 case ErrKeyColumnDoesNotExist.Is(err): 945 code = mysql.ERKeyColumnDoesNotExist 946 case ErrCantDropFieldOrKey.Is(err): 947 code = mysql.ERCantDropFieldOrKey 948 case ErrReadOnlyTransaction.Is(err): 949 code = 1792 // TODO: Needs to be added to vitess 950 case ErrCantDropIndex.Is(err): 951 code = 1553 // TODO: Needs to be added to vitess 952 case ErrInvalidValue.Is(err): 953 code = mysql.ERTruncatedWrongValueForField 954 case ErrUnknownColumn.Is(err): 955 code = mysql.ERBadFieldError 956 case ErrColumnSpecifiedTwice.Is(err): 957 code = mysql.ERFieldSpecifiedTwice 958 case ErrLockDeadlock.Is(err): 959 // ER_LOCK_DEADLOCK signals that the transaction was rolled back 960 // due to a deadlock between concurrent transactions. 961 // MySQL maps this error to the ANSI SQLSTATE code of 40001 which 962 // has the more general meaning of "serialization failure". 963 // https://mariadb.com/kb/en/mariadb-error-codes/ 964 // https://en.wikipedia.org/wiki/SQLSTATE 965 code = mysql.ERLockDeadlock 966 sqlState = mysql.SSLockDeadlock 967 default: 968 code = mysql.ERUnknownError 969 } 970 971 // This uses the given error as a format string, so we have to escape any percentage signs else they'll show up as "%!(MISSING)" 972 return mysql.NewSQLError(code, sqlState, strings.Replace(err.Error(), `%`, `%%`, -1)) 973 } 974 975 // UnwrapError removes any wrapping errors (e.g. WrappedInsertError) around the specified error and 976 // returns the first non-wrapped error type. 977 func UnwrapError(err error) error { 978 switch wrappedError := err.(type) { 979 case WrappedInsertError: 980 return UnwrapError(wrappedError.Cause) 981 case WrappedTypeConversionError: 982 return UnwrapError(wrappedError.Err) 983 default: 984 return err 985 } 986 } 987 988 type UniqueKeyError struct { 989 keyStr string 990 IsPK bool 991 Existing Row 992 } 993 994 func NewUniqueKeyErr(keyStr string, isPK bool, existing Row) error { 995 ue := UniqueKeyError{ 996 keyStr: keyStr, 997 IsPK: isPK, 998 Existing: existing, 999 } 1000 1001 if isPK { 1002 return ErrPrimaryKeyViolation.Wrap(ue) 1003 } else { 1004 return ErrUniqueKeyViolation.Wrap(ue) 1005 } 1006 } 1007 1008 func (ue UniqueKeyError) Error() string { 1009 return fmt.Sprintf("%s", ue.keyStr) 1010 } 1011 1012 type WrappedInsertError struct { 1013 OffendingRow Row 1014 Cause error 1015 } 1016 1017 func NewWrappedInsertError(r Row, err error) WrappedInsertError { 1018 return WrappedInsertError{ 1019 OffendingRow: r, 1020 Cause: err, 1021 } 1022 } 1023 1024 func (w WrappedInsertError) Error() string { 1025 return w.Cause.Error() 1026 } 1027 1028 // IgnorableError is used propagate information about an error that needs to be ignored and does not interfere with 1029 // any update accumulators 1030 type IgnorableError struct { 1031 OffendingRow Row 1032 } 1033 1034 func NewIgnorableError(row Row) IgnorableError { 1035 return IgnorableError{OffendingRow: row} 1036 } 1037 1038 func (e IgnorableError) Error() string { 1039 return "An ignorable error should never be printed" 1040 } 1041 1042 type WrappedTypeConversionError struct { 1043 OffendingVal interface{} 1044 OffendingIdx int 1045 Err error 1046 } 1047 1048 func NewWrappedTypeConversionError(offendingVal interface{}, idx int, err error) WrappedTypeConversionError { 1049 return WrappedTypeConversionError{OffendingVal: offendingVal, OffendingIdx: idx, Err: err} 1050 } 1051 1052 func (w WrappedTypeConversionError) Error() string { 1053 return w.Err.Error() 1054 }