qb icon indicating copy to clipboard operation
qb copied to clipboard

Postgres: processes GUID as string

Open GunnarLieb opened this issue 5 months ago • 0 comments

happened in megaphone with postgres 17 (even after upgrading qb to latest version).

This is q quick fix since I didn't know how to implement it properly

public any function runQuery(
        required string sql,
        array bindings = [],
        struct options = {},
        string returnObject = "result",
        any preExecutionHook,
        any postProcessHook,
        boolean pretend = false
    ) {
        // Process UUID bindings for PostgreSQL
        var processedBindings = arguments.bindings.map( function( binding ) {
            // Handle both simple values and binding structs
            var actualValue = isStruct( binding ) ? binding.value : binding;
            
            // Check if this looks like a UUID
            if ( isSimpleValue( actualValue ) && 
                 len( actualValue ) == 36 && 
                 reFind( "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$", actualValue ) ) {
                
                // Return a struct with the UUID value and PostgreSQL-specific type casting
                if ( isStruct( binding ) ) {
                    // Update existing binding struct
                    var newBinding = duplicate( binding );
                    newBinding.cfsqltype = "CF_SQL_OTHER";
                    newBinding.sqltype = "OTHER";
                    return newBinding;
                } else {
                    // Create new binding struct for simple value
                    return {
                        value: actualValue,
                        cfsqltype: "CF_SQL_OTHER",
                        sqltype: "OTHER",
                        list: false,
                        null: false
                    };
                }
            }
            return binding;
        } );
        
        // Call parent with processed bindings
        return super.runQuery(
            sql = arguments.sql,
            bindings = processedBindings,
            options = arguments.options,
            returnObject = arguments.returnObject,
            preExecutionHook = arguments.preExecutionHook,
            postProcessHook = arguments.postProcessHook,
            pretend = arguments.pretend
        );
    }```

GunnarLieb avatar Sep 10 '25 11:09 GunnarLieb