PostgreSQL-For-Wordpress / postgresql-for-wordpress

A maintained fork of https://wordpress.org/plugins/postgresql-for-wordpress/
GNU General Public License v2.0
220 stars 71 forks source link

implement wpsqli_fetch_field #64

Open mattbucci opened 10 months ago

mattbucci commented 10 months ago

https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress/blob/bf2ef7f4185d5327543ded7df42efb16ff79fa7c/pg4wp/driver_pgsql.php#L871C16-L871C16

/**
 * Returns the next field in the result set.
 *
 * This function is a wrapper for the pg_fetch_field function, which retrieves information about
 * the next field in the result set represented by the `$result` parameter. It can be used in a loop
 * to obtain information about each field in the result set, such as name, table, max length, flags,
 * and type. This is useful for dynamically generating table structures or processing query results
 * when the structure of the result set is not known in advance or changes.
 *
 * @param \PgSql\Result $result The result set returned by pg_query, pg_store_result
 *                              or pg_use_result.
 * @return object An object which contains field definition information or FALSE if no field information
 *                is available.
 */
function wpsqli_fetch_field($result)
{
    throw new \Exception("PG4WP: Not Yet Implemented");
    // mysqli_fetch_field => pg_field_table (resource $result, int $field_number, bool $oid_only = false): mixed
    // Returns the name or oid of the table of the field. There's no direct function to mimic mysqli_fetch_field completely.
    //pg_field_table($result, $field_number);
}
mattbucci commented 10 months ago

I recommend checking out @ezusoft's implementation here https://wordpress.org/support/topic/missing-function-wpsql_fetch_field/

class pg4fetch_field
    {
        public $name='empty';
        public $type='';
    }
    function wpsql_fetch_field($result, $num)
    {
        $objekt=new pg4fetch_field();
        $object->name = pg_field_name($result, $num);
        $object->type = pg_field_type($result, $num);
        return $object; 
    }

Note: The type conversion is probably not correct, since (mysql/pg)_field_type returns a text and mysql_fetch_field returns a number