/*
   Copyright (c) 2013, 2020, Oracle and/or its affiliates.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is also distributed with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have included with MySQL.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
*/

/* Errors returned by mysql-js are JavaScript Error objects.
   They contain:
     message: a string with a description of the problem
     stack: the locus of the error
     sqlstate: one of the Sqlstate values below
     cause: an Error returned by an underlying implementation artifact
*/

var DatabaseError = {
  code           : null,   // MySQL Error Code number (number)
  sqlstate       : null,   // SQLSTATE (string)
  message        : null,   // Error message (string)
  cause          : null,   // The underlying cause of this error
  /* ...  Other adapter-specific properties which may be present */
};



// Reference: Gulutzan & Pelzer, "SQL 99 Complete Really", chapter 47

var Sqlstates = {
  /* Standard-defined classes, SQL-99 */
  "02000" : "No Data",

  // connection errors
  "08000" : "Connection error",
  "08001" : "Unable to connect to server",
  "08004" : "Connection refused",

  // data errors
  "22000" : "Data error",
  "22001" : "String too long",
  "22003" : "Numeric value out of range",
  "22007" : "Invalid datetime",
  
  // Constraint violations
  // 23000 includes both duplicate primary key and duplicate unique key
  "23000" : "Integrity Constraint Violation",

  // 0Fxxx "Locator Exception" SQLStates relate to BLOB values
  // (which must represented in JavaScript as Node Buffers)
  "0F001" : "Invalid BLOB value",

  // misc. errors
  "25000" : "Invalid Transaction State",  
  "2C000" : "Invalid character set name",  
  "42S02" : "Table not found",
  "IM001" : "Driver does not support this function",  
  
  /* Implementation-defined classes (NDB) */
  "NDB00" : "Refer to ndb_error for details",
  "WCTOR" : "Object clobbered by Domain Object Constructor"
};

