Changeset 985 for trunk/pgmodule.c


Ignore:
Timestamp:
Apr 22, 2019, 6:07:43 PM (4 months ago)
Author:
cito
Message:

Let single() and variants raise more specific error

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pgmodule.c

    r983 r985  
    4343static PyObject *Error, *Warning, *InterfaceError, *DatabaseError,
    4444                *InternalError, *OperationalError, *ProgrammingError,
    45                 *IntegrityError, *DataError, *NotSupportedError;
     45                *IntegrityError, *DataError, *NotSupportedError,
     46                *InvalidResultError, *NoResultError, *MultipleResultsError;
    4647
    4748#define _TOSTRING(x) #x
     
    46134614"The single row from the query result is returned as a tuple of fields.\n"
    46144615"This method returns the same single row when called multiple times.\n"
    4615 "It raises a ProgrammingError if the result does not have exactly one row.\n";
     4616"It raises an InvalidResultError if the result doesn't have exactly one row,\n"
     4617"which will be of type NoResultError or MultipleResultsError specifically.\n";
    46164618
    46174619static PyObject *
     
    46214623
    46224624    if (self->max_row != 1) {
    4623         set_error_msg(ProgrammingError,
    4624             self->max_row ? "Multiple results found" : "No result found");
     4625        if (self->max_row)
     4626            set_error_msg(MultipleResultsError, "Multiple results found");
     4627        else
     4628            set_error_msg(NoResultError, "No result found");
    46254629        return NULL;
    46264630    }
     
    47284732"the field names used as the keys.\n"
    47294733"This method returns the same single row when called multiple times.\n"
    4730 "It raises a ProgrammingError if the result does not have exactly one row.\n";
     4734"It raises an InvalidResultError if the result doesn't have exactly one row,\n"
     4735"which will be of type NoResultError or MultipleResultsError specifically.\n";
    47314736
    47324737static PyObject *
     
    47364741
    47374742    if (self->max_row != 1) {
    4738         set_error_msg(ProgrammingError,
    4739             self->max_row ? "Multiple results found" : "No result found");
     4743        if (self->max_row)
     4744            set_error_msg(MultipleResultsError, "Multiple results found");
     4745        else
     4746            set_error_msg(NoResultError, "No result found");
    47404747        return NULL;
    47414748    }
     
    48174824"The single row from the query result is returned as named tuple of fields.\n"
    48184825"This method returns the same single row when called multiple times.\n"
    4819 "It raises a ProgrammingError if the result does not have exactly one row.\n";
     4826"It raises an InvalidResultError if the result doesn't have exactly one row,\n"
     4827"which will be of type NoResultError or MultipleResultsError specifically.\n";
    48204828
    48214829static PyObject *
     
    48274835
    48284836    if (self->max_row != 1) {
    4829         set_error_msg(ProgrammingError,
    4830             self->max_row ? "Multiple results found" : "No result found");
     4837        if (self->max_row)
     4838            set_error_msg(MultipleResultsError, "Multiple results found");
     4839        else
     4840            set_error_msg(NoResultError, "No result found");
    48314841        return NULL;
    48324842    }
     
    49694979"Returns the first field of the next row from the result as a scalar value.\n"
    49704980"This method returns the same single row when called multiple times.\n"
    4971 "It raises a ProgrammingError if the result does not have exactly one row.\n";
     4981"It raises an InvalidResultError if the result doesn't have exactly one row,\n"
     4982"which will be of type NoResultError or MultipleResultsError specifically.\n";
    49724983
    49734984static PyObject *
     
    49824993
    49834994    if (self->max_row != 1) {
    4984         set_error_msg(ProgrammingError,
    4985             self->max_row ? "Multiple results found" : "No result found");
     4995        if (self->max_row)
     4996            set_error_msg(MultipleResultsError, "Multiple results found");
     4997        else
     4998            set_error_msg(NoResultError, "No result found");
    49864999        return NULL;
    49875000    }
     
    62016214    PyDict_SetItemString(dict, "Warning", Warning);
    62026215
    6203     InterfaceError = PyErr_NewException("pg.InterfaceError", Error, NULL);
     6216    InterfaceError = PyErr_NewException(
     6217        "pg.InterfaceError", Error, NULL);
    62046218    PyDict_SetItemString(dict, "InterfaceError", InterfaceError);
    62056219
    6206     DatabaseError = PyErr_NewException("pg.DatabaseError", Error, NULL);
     6220    DatabaseError = PyErr_NewException(
     6221        "pg.DatabaseError", Error, NULL);
    62076222    PyDict_SetItemString(dict, "DatabaseError", DatabaseError);
    62086223
    6209     InternalError =
    6210         PyErr_NewException("pg.InternalError", DatabaseError, NULL);
     6224    InternalError = PyErr_NewException(
     6225        "pg.InternalError", DatabaseError, NULL);
    62116226    PyDict_SetItemString(dict, "InternalError", InternalError);
    62126227
    6213     OperationalError =
    6214         PyErr_NewException("pg.OperationalError", DatabaseError, NULL);
     6228    OperationalError = PyErr_NewException(
     6229        "pg.OperationalError", DatabaseError, NULL);
    62156230    PyDict_SetItemString(dict, "OperationalError", OperationalError);
    62166231
    6217     ProgrammingError =
    6218         PyErr_NewException("pg.ProgrammingError", DatabaseError, NULL);
     6232    ProgrammingError = PyErr_NewException(
     6233        "pg.ProgrammingError", DatabaseError, NULL);
    62196234    PyDict_SetItemString(dict, "ProgrammingError", ProgrammingError);
    62206235
    6221     IntegrityError =
    6222         PyErr_NewException("pg.IntegrityError", DatabaseError, NULL);
     6236    IntegrityError = PyErr_NewException(
     6237        "pg.IntegrityError", DatabaseError, NULL);
    62236238    PyDict_SetItemString(dict, "IntegrityError", IntegrityError);
    62246239
    6225     DataError = PyErr_NewException("pg.DataError", DatabaseError, NULL);
     6240    DataError = PyErr_NewException(
     6241        "pg.DataError", DatabaseError, NULL);
    62266242    PyDict_SetItemString(dict, "DataError", DataError);
    62276243
    6228     NotSupportedError =
    6229         PyErr_NewException("pg.NotSupportedError", DatabaseError, NULL);
     6244    NotSupportedError = PyErr_NewException(
     6245        "pg.NotSupportedError", DatabaseError, NULL);
    62306246    PyDict_SetItemString(dict, "NotSupportedError", NotSupportedError);
     6247
     6248    InvalidResultError = PyErr_NewException(
     6249        "pg.InvalidResultError", DataError, NULL);
     6250    PyDict_SetItemString(dict, "InvalidResultError", InvalidResultError);
     6251
     6252    NoResultError = PyErr_NewException(
     6253        "pg.NoResultError", InvalidResultError, NULL);
     6254    PyDict_SetItemString(dict, "NoResultError", NoResultError);
     6255
     6256    MultipleResultsError = PyErr_NewException(
     6257        "pg.MultipleResultsError", InvalidResultError, NULL);
     6258    PyDict_SetItemString(dict, "MultipleResultsError", MultipleResultsError);
    62316259
    62326260    /* Make the version available */
Note: See TracChangeset for help on using the changeset viewer.