Пример #1
0
    def _format_field_value(self, field_name) -> str:
        """Formats a field's value for usage in SQL.

        Arguments:
            field_name:
                The name of the field to format
                the value of.

        Returns:
            The field's value formatted for usage
            in SQL.
        """

        field_name = self._normalize_field_name(field_name)
        field = self._get_model_field(field_name)

        return SQLInsertCompiler.prepare_value(
            self,
            field,
            # Note: this deliberately doesn't use `pre_save_val` as we don't
            # want things like auto_now on DateTimeField (etc.) to change the
            # value. We rely on pre_save having already been done by the
            # underlying compiler so that things like FileField have already had
            # the opportunity to save out their data.
            getattr(self.query.objs[0], field.attname))
    def test_PGCRYPT_KEY_setting_per_database_decrypt(self, db, model, vals):
        conn = connections['secondary']
        obj = model(value=vals[0])
        field = obj._meta.get_field('value')
        col = field.get_col(obj._meta.db_table)
        query = Query(model)
        compiler = SQLInsertCompiler(query, conn, 'secondary')
        sql, params = col.as_sql(compiler, conn)

        assert 'secondary_key' in sql
Пример #3
0
    def _format_field_value(self, field_name) -> str:
        """Formats a field's value for usage in SQL.

        Arguments:
            field_name:
                The name of the field to format
                the value of.

        Returns:
            The field's value formatted for usage
            in SQL.
        """

        field_name = self._normalize_field_name(field_name)
        field = self._get_model_field(field_name)

        return SQLInsertCompiler.prepare_value(
            self, field, getattr(self.query.objs[0], field_name))
Пример #4
0
def placeholder(self, conn, field, value):
    if isinstance(value, Now):
        return value.as_sql(None, conn)[0]
    else:
        return SQLInsertCompiler.placeholder(self, field, value)
Пример #5
0
def placeholder(self, conn, field, value):
    if isinstance(value, Now):
        return value.as_sql(None, conn)[0]
    else:
        return SQLInsertCompiler.placeholder(self, field, value)