示例#1
0
    def __prepare(self, cursor: DictCursor, sql: str,
                  double_percentage_sign_marker: str) -> None:
        """Prepare statement."""

        sql = decode_object_from_bytes_if_needed(sql)

        if sql is None:
            raise McPrepareException("SQL is None.")
        if len(sql) == '':
            raise McPrepareException("SQL is empty.")

        self.__sql = sql
        self.__arguments = collections.OrderedDict()
        self.__cursor = cursor
        self.__double_percentage_sign_marker = double_percentage_sign_marker
示例#2
0
    def __bind(self, param_num: int, value: Any) -> None:
        """Underlying implementation of bind(); doesn't do any decoding or preprocessing."""

        if param_num < 1:
            raise McPrepareException("Parameter number must be >1.")

        self.__arguments[param_num] = value
示例#3
0
    def execute(self) -> DatabaseResult:
        """Execute prepared statement."""

        query_args = [self.__sql]
        expected_param_num = 1
        for param_num, param_value in self.__arguments.items():
            query_args.append(param_value)

            if param_num != expected_param_num:
                raise McPrepareException("Invalid parameter number %d" %
                                         param_num)
            expected_param_num += 1

        query_args = convert_dbd_pg_arguments_to_psycopg2_format(
            *query_args, skip_decoding=True)

        return DatabaseResult(
            cursor=self.__cursor,
            query_args=query_args,
            double_percentage_sign_marker=self.__double_percentage_sign_marker)
示例#4
0
 def bind_bytea(self, param_num: int, value: bytes) -> None:
     """Bind BYTEA value as statement's parameter."""
     if not isinstance(value, bytes):
         raise McPrepareException("Value '%s' is not 'bytes'." % str(value))
     self.__bind(param_num=param_num, value=value)