Customizing existing generators
Published 04 February 2013
You can customize the generators in the following ways:
- change the settings for each column
- for generators that use lists, create a custom list of values
Changing the settings
When you select a generator for a column, you can customize the generator by changing the default settings.
For example, in the Personal category, Working Age is pre-configured to have a minimum value of 18 and a maximum value of 65. However, in your company the minimum age may be 21, so you can change this value in Min.
Similarly, if you have selected the Title generator, you may want to add the title Prof. To do this, you can edit the expression in Regular expression. Change:
Mr|((Mrs|Miss|Ms)|Dr)(\.?)
To:
Mr|((Mrs|Miss|Ms)|Dr|Prof)(\.?)
For more information about regular expression generators, see: Regexp generator.
This is a good way to customize a generator for an individual column.
Creating custom lists
Some of the generators use lists of values (dictionaries) to supply the data. For example, First Name (Female) uses the list NamesFirstFemale.txt
The lists are located in %ProgramFiles%\Red Gate\SQL Data Generator 2\Config (on 32-bit machines) or %ProgramFiles(x86)%\Red Gate\SQL Data Generator 2\Config (on 64-bit machines).
You can create your own lists by creating a text file with each value on a new line. You can then amend the generator settings so that it uses your file. For example, for First Name (Female), click Browse... to select your file. Alternatively, you can use the generic File List generator.
For generators that use regular expressions such as Full Names, edit the regular expression to specify the name of the new text file.
For more information about regular expression generators, see: Regexp generator.
If you will want to use the generator with the custom list again, you can create a new generator that references the custom list file, see: Creating a custom generator.
Creating a custom generator
You may find that you want to make the same customizations for a number of columns. In this case, you can customize a generator and add it to the list of available generators so that you can re-use it.
To do this, find the SQL type or generic generator that you want to base the custom generator on, and then find its corresponding .xml file in %ProgramFiles%\Red Gate\SQL Data Generator 2\UserExample\Config (on 32-bit machines) or %ProgramFiles(x86)%\Red Gate\SQL Data Generator 2\UserExample\Config (on 64-bit machines).
Create a copy of the .xml file and name it appropriately, then edit the contents to specify the properties as required.
The example below shows the code for the Working Age generator which generates random integers between 18 and 65. It is based on Int32Generator.xml:
<?xml version="1.0" encoding="iso-8859-1"?> <generators> <generator /* Specify the class. */ type="RedGate.SQLDataGenerator.Generators.Number.Int32Generator" /* The name and description to be displayed in the generators list, */ /* and its category */ name="Working Age" description="29,30,35,18..." category="Personal"> /* Set the properties for the generator. */ <property name="MinValue">18</property> <property name="MaxValue">65</property> /* Specify the columns that match, and their score. */ <matches field="Age" score="50"/> /* Define the data types for which the generator is valid. */ <type type="Int64"/> <type type="Int32"/> <type type="Int16"/> <type type="Byte"/> </generator>
SQL Data Generator uses the matches field string when it allocates the generators to columns. You can specify a regular expression search string. You then specify a score; if more than one generator matches a particular column, SQL Data Generator uses the one with the highest score.