You are here : cpp0mysql_sqlstate

mysql_sqlstate() - 0

 Returns a null-terminated string containing the SQLSTATE error
        code for the most recently executed SQL statement. The error
        code consists of five characters. '00000'
        means “no error.” The values are specified by ANSI
        SQL and ODBC. For a list of possible values, see
        Appendix B, Errors, Error Codes, and Common Problems.'00000'“no error.”no error.Appendix B, Errors, Error Codes, and Common ProblemsErrors, Error Codes, and Common ProblemsSQLSTATE values returned by
        mysql_sqlstate() differ from
        MySQL-specific error numbers returned by
        mysql_errno(). For example, the
        mysql client program displays errors using
        the following format, where 1146 is the
        mysql_errno() value and
        '42S02' is the corresponding
        mysql_sqlstate() value:mysql_sqlstate()mysql_sqlstate()mysql_errno()mysql_errno()mysqlmysqlmysql1146mysql_errno()mysql_errno()'42S02'mysql_sqlstate()mysql_sqlstate()shell> SELECT * FROM no_such_table;
ERROR 1146 (42S02): Table 'test.no_such_table' doesn't existSELECT * FROM no_such_table;SELECT * FROM no_such_table;Not all MySQL error numbers are mapped to SQLSTATE error codes.
        The value 'HY000' (general error) is used for
        unmapped error numbers.'HY000'If you call mysql_sqlstate()
        after mysql_real_connect()
        fails, mysql_sqlstate() might
        not return a useful value. For example, this happens if a host
        is blocked by the server and the connection is closed without
        any SQLSTATE value being sent to the client.mysql_sqlstate()mysql_sqlstate()mysql_real_connect()mysql_real_connect()mysql_sqlstate()mysql_sqlstate()


Syntax

const char *mysql_sqlstate(MYSQL *mysql)


Example

shell> SELECT * FROM no_such_table;
ERROR 1146 (42S02): Table 'test.no_such_table' doesn't exist


Output / Return Value

 A null-terminated character string containing the SQLSTATE error
        code.See Section 25.8.7.14, “mysql_errno()”,
        Section 25.8.7.15, “mysql_error()”, and
        Section 25.8.11.27, “mysql_stmt_sqlstate()”.Section 25.8.7.14, “mysql_errno()”Section 25.8.7.15, “mysql_error()”Section 25.8.11.27, “mysql_stmt_sqlstate()”


Limitations


Alternatives / See Also


Reference