This repository has been archived on 2025-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
lwb6/legacyworlds-server-data/db-structure/tests/utils/resources.sql

63 lines
1.4 KiB
MySQL
Raw Normal View History

/*
* Utility functions used by unit tests
*
* Resources and natural resources
*/
/*
* Function that creates some quantity of resources
* All resources are created using the specified prefix for the strings
*/
CREATE FUNCTION _create_resources( _quantity INT , _prefix TEXT )
RETURNS VOID
AS $$
DECLARE
i INT;
BEGIN
PERFORM _create_test_strings( _quantity , _prefix );
PERFORM _create_test_strings( _quantity , _prefix || 'Description' );
i := 0;
WHILE i < _quantity
LOOP
i := i + 1;
INSERT INTO defs.resources (
resource_name_id , resource_description_id , resource_weight
) VALUES (
_get_string( _prefix || i::TEXT ) ,
_get_string( _prefix || 'Description' || i::TEXT ) ,
i
);
END LOOP;
END;
$$ LANGUAGE PLPGSQL;
/*
* Function that creates some quantity of /natural/ resources
* All resources are created using the specified prefix for the strings
*/
CREATE FUNCTION _create_natural_resources( _quantity INT , _prefix TEXT )
RETURNS VOID
AS $$
DECLARE
i INT;
BEGIN
PERFORM _create_resources( _quantity , _prefix );
i := 0;
WHILE i < _quantity
LOOP
i := i + 1;
INSERT INTO defs.natural_resources(
resource_name_id , natres_p_presence , natres_quantity_avg ,
natres_quantity_dev , natres_difficulty_avg ,
natres_difficulty_dev , natres_recovery_avg ,
natres_recovery_dev
) VALUES (
_get_string( _prefix || i::TEXT ) , 0.5 , 100 , 1 , 0.5 , 0.05 , 0.5 , 0.05
);
END LOOP;
END;
$$ LANGUAGE PLPGSQL;