@@ -675,14 +675,14 @@ ean2string(ean13 ean, bool errorOK, char *result, bool shortType)
675
675
/*
676
676
* string2ean --- try to parse a string into an ean13.
677
677
*
678
- * If errorOK is false, ereport a useful error message if the string is bad.
679
- * If errorOK is true, just return "false" for bad input .
678
+ * ereturn false with a useful error message if the string is bad.
679
+ * Otherwise return true .
680
680
*
681
681
* if the input string ends with '!' it will always be treated as invalid
682
682
* (even if the check digit is valid)
683
683
*/
684
684
static bool
685
- string2ean (const char * str , bool errorOK , ean13 * result ,
685
+ string2ean (const char * str , struct Node * escontext , ean13 * result ,
686
686
enum isn_type accept )
687
687
{
688
688
bool digit ,
@@ -876,48 +876,38 @@ string2ean(const char *str, bool errorOK, ean13 *result,
876
876
return true;
877
877
}
878
878
879
- if (! errorOK )
879
+ if (rcheck == ( unsigned ) -1 )
880
880
{
881
- if (rcheck == (unsigned ) -1 )
882
- {
883
- ereport (ERROR ,
884
- (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
885
- errmsg ("invalid %s number: \"%s\"" ,
886
- isn_names [accept ], str )));
887
- }
888
- else
889
- {
890
- ereport (ERROR ,
891
- (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
892
- errmsg ("invalid check digit for %s number: \"%s\", should be %c" ,
893
- isn_names [accept ], str , (rcheck == 10 ) ? ('X' ) : (rcheck + '0' ))));
894
- }
881
+ ereturn (escontext , false,
882
+ (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
883
+ errmsg ("invalid %s number: \"%s\"" ,
884
+ isn_names [accept ], str )));
885
+ }
886
+ else
887
+ {
888
+ ereturn (escontext , false,
889
+ (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
890
+ errmsg ("invalid check digit for %s number: \"%s\", should be %c" ,
891
+ isn_names [accept ], str , (rcheck == 10 ) ? ('X' ) : (rcheck + '0' ))));
895
892
}
896
- return false;
897
893
898
894
eaninvalid :
899
- if (!errorOK )
900
- ereport (ERROR ,
901
- (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
902
- errmsg ("invalid input syntax for %s number: \"%s\"" ,
903
- isn_names [accept ], str )));
904
- return false;
895
+ ereturn (escontext , false,
896
+ (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
897
+ errmsg ("invalid input syntax for %s number: \"%s\"" ,
898
+ isn_names [accept ], str )));
905
899
906
900
eanwrongtype :
907
- if (!errorOK )
908
- ereport (ERROR ,
909
- (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
910
- errmsg ("cannot cast %s to %s for number: \"%s\"" ,
911
- isn_names [type ], isn_names [accept ], str )));
912
- return false;
901
+ ereturn (escontext , false,
902
+ (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
903
+ errmsg ("cannot cast %s to %s for number: \"%s\"" ,
904
+ isn_names [type ], isn_names [accept ], str )));
913
905
914
906
eantoobig :
915
- if (!errorOK )
916
- ereport (ERROR ,
917
- (errcode (ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE ),
918
- errmsg ("value \"%s\" is out of range for %s type" ,
919
- str , isn_names [accept ])));
920
- return false;
907
+ ereturn (escontext , false,
908
+ (errcode (ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE ),
909
+ errmsg ("value \"%s\" is out of range for %s type" ,
910
+ str , isn_names [accept ])));
921
911
}
922
912
923
913
/*----------------------------------------------------------
@@ -952,7 +942,7 @@ isn_out(PG_FUNCTION_ARGS)
952
942
char * result ;
953
943
char buf [MAXEAN13LEN + 1 ];
954
944
955
- (void ) ean2string (val , false , buf , true);
945
+ (void ) ean2string (val , fcinfo -> context , buf , true);
956
946
957
947
result = pstrdup (buf );
958
948
PG_RETURN_CSTRING (result );
@@ -968,7 +958,7 @@ ean13_out(PG_FUNCTION_ARGS)
968
958
char * result ;
969
959
char buf [MAXEAN13LEN + 1 ];
970
960
971
- (void ) ean2string (val , false , buf , false);
961
+ (void ) ean2string (val , fcinfo -> context , buf , false);
972
962
973
963
result = pstrdup (buf );
974
964
PG_RETURN_CSTRING (result );
@@ -983,7 +973,8 @@ ean13_in(PG_FUNCTION_ARGS)
983
973
const char * str = PG_GETARG_CSTRING (0 );
984
974
ean13 result ;
985
975
986
- (void ) string2ean (str , false, & result , EAN13 );
976
+ if (!string2ean (str , fcinfo -> context , & result , EAN13 ))
977
+ PG_RETURN_NULL ();
987
978
PG_RETURN_EAN13 (result );
988
979
}
989
980
@@ -996,7 +987,8 @@ isbn_in(PG_FUNCTION_ARGS)
996
987
const char * str = PG_GETARG_CSTRING (0 );
997
988
ean13 result ;
998
989
999
- (void ) string2ean (str , false, & result , ISBN );
990
+ if (!string2ean (str , fcinfo -> context , & result , ISBN ))
991
+ PG_RETURN_NULL ();
1000
992
PG_RETURN_EAN13 (result );
1001
993
}
1002
994
@@ -1009,7 +1001,8 @@ ismn_in(PG_FUNCTION_ARGS)
1009
1001
const char * str = PG_GETARG_CSTRING (0 );
1010
1002
ean13 result ;
1011
1003
1012
- (void ) string2ean (str , false, & result , ISMN );
1004
+ if (!string2ean (str , fcinfo -> context , & result , ISMN ))
1005
+ PG_RETURN_NULL ();
1013
1006
PG_RETURN_EAN13 (result );
1014
1007
}
1015
1008
@@ -1022,7 +1015,8 @@ issn_in(PG_FUNCTION_ARGS)
1022
1015
const char * str = PG_GETARG_CSTRING (0 );
1023
1016
ean13 result ;
1024
1017
1025
- (void ) string2ean (str , false, & result , ISSN );
1018
+ if (!string2ean (str , fcinfo -> context , & result , ISSN ))
1019
+ PG_RETURN_NULL ();
1026
1020
PG_RETURN_EAN13 (result );
1027
1021
}
1028
1022
@@ -1035,7 +1029,8 @@ upc_in(PG_FUNCTION_ARGS)
1035
1029
const char * str = PG_GETARG_CSTRING (0 );
1036
1030
ean13 result ;
1037
1031
1038
- (void ) string2ean (str , false, & result , UPC );
1032
+ if (!string2ean (str , fcinfo -> context , & result , UPC ))
1033
+ PG_RETURN_NULL ();
1039
1034
PG_RETURN_EAN13 (result );
1040
1035
}
1041
1036
0 commit comments