1、数据自动生成工具 DataFactory 使用文档版本 修订文档历史记录日期 版本 说明 作者2012-12-23 1.0 初稿 张昌平用户指南Datafactory工具是 Quest公司(http:/)旗下的产品,它能够根据用户定制,产生或导入需要的数据,插入相应的数据表或导出至外部文件。Quest DataFactory 是一种快速的、易于产生测试数据工具,它能建模复杂数据关系,且有带有 GUI界面。DataFactory 是一个功能强大的数据产生器,它允许开发人员和 QA毫不费力地产生百万行有意义的测试数据。随机数据的例子包括随机数字,随机字符,并随机日期。有意义的数据包括名字,姓氏,城
2、市,州和邮政编码。工作原理:DataFactory首先读取数据库中表的模式,即表的定义之类的内容,以列表的形式显示,如它的表和字段的数据库对象。然后由用户定制要产生数据的具体内容,如数字范围、字符串长度、要产生数据记录的个数等等,最后运行工程,生成数据。DataFactory支持的数据库类型有:DB2、SQL Server、Oracle,ODBC 数据源以及 Sybase。设置 ODBC数据源的方法,即添加待操作的数据源(开始-控制面板-管理工具-ODBC 数据源) 。一、介绍1、Option 选项:暂停数据产生。:停止数据产生。:设置数据依赖的时间与当前时间的偏移。:创建数据表。系统设置在
3、View菜单下 Option选项:2、DataFactory 可以运行在命令行,在加载和运行的项目文件选项。在/ p 标志可用于指定要加载的项目。在/ r 标志可以用来显示该项目运行后,应加载它。一个可选的延迟可以指定与/ R 参数表明,项目的实施应推迟 n 分钟。The following example runs DataFactory and loads a project:dfactory /p c:projectsnewproject.txfThe following example runs DataFactory, loads and runs a project:dfactor
4、y /p c:projectsnewproject.txf /rThe following example runs DataFactory, loads a project, sleeps for 10 hours, then runs the project:dfactory /p c:projectsnewproject.txf /r 600 Starting DataFactory from the Command LineDataFactory can be run from the command line with the option of loading and runnin
5、g project files. The following flag is provided: The /x flag can be used to indicate that the project should be run after it is loadedNote: You must be in the DataFactory directory to run from the command line. For example: C:Program FilesQuest SoftwareDataFactorybinExample Syntaxdfactory “projectfi
6、le“ /xCommand Line ExamplesTo start DataFactory without loading a projectdfactory To start DataFactory and load a projectdfactory c:projectsnewproject.dfsTo start DataFactory, load, and run a projectdfactory c:projectsnewproject.dfs /xNote: If the path contains spaces, it must be enclosed in quotes.
7、 For example: dfactory “c:my projectsnew project.dfs“3、Age:老龄化数据数据老化搬迁日期字段的值前进和后退的过程。一个典型的老龄化数据的使用将是创建一个测试数据设置使用当前的日期,然后运行的有关数据和测试结果的捕获设置。然后,数据可以来岁的一个关键日期和测试可以重新运行是否符合规定。DataFactory 提供了三种数据日期字段老化选择。 Do not age the field Age the field using default options Age the field using custom options二、数据库对象数据库
8、属性对话框:数据库有下列属性NameUser IDAuto-Delete(工程运行前自动清除表中的原有数据)当这个选项被选中,先前在该项目中所包含的所有表生成的数据会被删除。这些表会按照数据库的引用完整性进行删除。Scan for dependencies and include related tables(自动包含与选中的表相关联的表)当创建一个项目,DataFactory 可以选择扫描 primary-key/foreign 重要关系,包括相关的表,地图在项目表关系。用户至少包含一个表中的项目和DataFactory 将包括所有直接或间接相关的包括表表。外键将被映射到主的相关表键。主键将
9、自动设置产生独特的数值数据领域和独特的字符串字符字段序列。Available Tables Included TablesChanging Table Order 更改表的顺序表将被装载的顺序,他们在包括表列表中。如果您使用的临时数据表或运行SQL 语句的执行时间,从一个表中插入到另一个产生的数据,那么重要的是,源表之前,目标表执行。要更改表的顺序,选择一个表,然后单击上移或下移按钮。Enclose Field Names 字段名称括一些数据库可以空白将在包括一个字段名称,例如:名字。此功能通常是由一名语法,允许字段名称被围封,例如:名字。如果数据库支持此功能,你希望有封闭式你可以打开此选项字
10、段名称,并输入开始和结束字符。Enclose Table Names 附上表名有些数据库允许的空白将在包括一个表名,例如:订单细节。此功能通常是由一名语法,允许表名被围封,例如:订单明细。如果数据库支持此功能,你希望有封闭式你可以打开此选项表名称,并输入开始和结束字符。Execute SQL Script Before and After Project Execution指定 SQL 将之前和之后的表填充执行脚本。用户可以指定文件包含 SQL 脚本,并在运行时,该文件将被打开,该脚本执行。还有一个编辑按钮,将打开 SQL脚本使用 SQL 文件关联的应用程序。此功能的一些可能的用途包括: 在数
11、据插入之前,执行一个脚本用于删除或重新创建表。这可能是一个更有效的替代自动删除。 执行一个脚本删除限制,并在表上执行 truncate。这可能是一个更有效的替代自动删除。 执行一个前脚本删除触发器和一个后 脚本替换触发器。 执行一个前脚本删除索引和一个后 脚本替换索引。 执行一个后脚本修改刚刚创建的数据。三、表对象表属性有Name RecordsNoteCreate temporary data table临时数据表可用于将一个表生成的数据回传到另一个表中。此选项的目的是为了方便一个表有多个外键,这些外键参照字段来自多个表。如果选择此选项,一个临时数据表将被创建,可用于向项目中的其他表插入数据
12、。临时数据表与常规数据表一样,只是它们带前缀波形符字符() ,而且他们被删除当应用程序退出时。Available FieldsIncluded FieldsField Order 顺序See the section on the FIELD Token under Insert Value from SQL Database Table to understand how field order can be important.Output页面,设置导出行为:Child Table 子表子表是一个依赖于其他表(父表)的表。子表和父表之间的关系可以是一对一,或一对多。要创建两个表之间的关系,右
13、击父表对象,并从菜单中选择 New Child Table。将显示子表对话框。子表的一般特性与正常表非常相似,但以下情况除外。Records:要插入的记录的数目可通过设置一系列低和高范围变量。要始终插入相同数量的记录,设置范围和低高度范围为相同的值。Relationship Properties:关系属性子表有一个附加的属性页,题为关系。这是您定义两个表之间的关系的地方。关系页面包含一个两列格。第一列表示子表的主键,第二个是父表的主键。要定义关系,在第一列中选择字段或多个字段。然后在父表中选择一个或多个字段中。例如:在图示描述的例子中,表 df_customers 和 df_orders 有一
14、个一对多的关系,他们基于关键字段 custid。当项目运行,对于每一个插入 df_customers 表中的记录,1 至 5 条记录(与 df_customers 表中 custid 相匹配的记录)将被插入 df_orders 表中。这实际上模拟数据库中的每个客户 customers 将有 1 至 5条订单 orders。四、字段定义数据时,要考虑现有数据库表的约束,例如不可重复,不可为空等。数据表之间存在主外键关系时,应注意添加表的顺序并统一产生数据的方式,包含主键的表应先与外见表执行,否则将报错。数据设置面板分为两个部分,数据产生方式设置和数据格式设置。常用的数据产生方式有:Numeric
15、:Numeric的数据产生方式有六种:它们分别是:从数据表插入数据,这里的数据表是系统提供的。从数据库插入数据,我们需要自己编写 SQL语句从数据库中提取数据。用表达式产生数据,我们可以编写表达式,系统将使用结果生成数据。表达式中允许使用的运算符和格式请参见附录。插入连续的值,我们能够设定种子及增长值的大小,系统自动计算结果,如:种子为 1,增长值为 2,则产生的数据序列为 1,3,5,7插入随机值,我们可以设置其范围,则结果大小在设定范围之内。插入常量,结果将为常量值Text:Text的数据产生方式也有六种它们分别是:从数据表中插入数据。从数据库中插入数据。从外部文件中插入数据。插入随机的字
16、符组合,可以设置字符组合的长度。插入常量字符串插入组合文本,可以插入文本,数字,日期时间混合的文本。Date/Time:Date/Time的数据产生方式有五种它们分别是:从数据表中插入数据。从数据库中插入数据插入连续的时间,可以指定起始时间和增长时间。插入随机的时间,可以设置时间范围插入当前系统时间数据库中除上述三种数据类型外,还有许多其他的数据类型。When fields are included in a project, they will automatically be assigned a set of default properties based on data type.
17、The default properties are as follows: Text fields will be filled with random characters Numeric fields will be filled with a random number between 0 and the maximum for the data type Data / Time fields will be filled with the current system date and time 一、 Text FieldsExtract a portion of the text选
18、择此选项,插入一个子文本字符串。Case强制大写,小写,或混合的情况。Unique这个选项设置生成唯一值。KeySpecifies a collection of fields that, as a whole, must be unique, but do not have to be individually unique. Null Probability 空概率决定这个字段生成空字段的概率。比如,值 20 将会导致大约 20%的行的值为空。OptionThis is the method DataFactory will use to generate the field value.
19、 The available options are as follows: Insert text from a data table Insert text from a SQL database table Insert text from a file Insert random characters Insert a string constant Build a composite field 1、 Inserting Values From a Data Table DataFactory comes with several data tables that contain F
20、irst Names, Last Names, Cities, States and other useful kinds of data. Select this option to insert a value from one of these tables. See DataFactory Data Tables to learn how to create your own data tables.The following properties are associated with the Data Table option: Data Table The data table
21、from which the value will be selected. Field The field in the data table from which the value will be selected. Option There are three options associated with fields that obtain values from DataFactory Data Tables. The options are: Select a record at random - this will randomly select a record from
22、the Data Table Select records sequentially - this will select records in the order that they occur in the data table Synchronize with other fields from the same table - this will use the same record that was used for the first field in the table (in the order that the fields occur in the project) th
23、at uses the same Data Table 与同一个表中的其他字段同步-这将使用相同的数据表的第一个记录字段 (以字段在项目中出现的顺序)2、 Inserting Values From a SQL database table 此选项允许 SQL 语句指定将执行在运行时生成的字段值。 DataFactory 可以在运行时插入 SQL 语句来执行某些操作。There are currently two tokens available, FIELD and RAND which can be abbreviated F and R. Tokens and their associa
24、ted arguments are embedded in the SQL statement and enclosed with braces ( ). 目前有两种标记可用,FIELD and RAND,可以被缩写为 F 和 R。标记及其相关参数被嵌入在 SQL 语句和括号()中。FIELD Token The FIELD token allows another field in the table to specified. The value that DataFactory generated for that field will be inserted into the SQL
25、statement at run-time. FIELD 标记允许其他的字段在表中被指定。 DataFactory 为该字段生成的值将被在运行时插入到 SQL 语句。例如,假设您有一个 Description 字段和一个 ID 字段,并为 Description 字段指定以下的 SQL 语句:select ProductDescription from products where ProductID = F:ID If DataFactory generates the value 555 for the ID field, then the following SQL will be ex
26、ecuted to generate the Description field: select ProductDescription from products where ProductID = 555 注意:为了使此选项正常工作,在标记中引用的字段必须在用 SQL 语句生成值之前生成。所以需要对表中的字段进行排序。RAND Token RAND 标记被在运行时随机生成特定范围内的数值替换。Example select ProductDescription from products where ProductID = R:1:500 In this example the R:1:500
27、 will be replaced with a number between 1 and 500 The random token can include an optional third argument that specifies how many decimal places the generated value will contain. If the parameter is omitted, the default is zero. For example: 随机标记可以包括一个可选的第三个参数,它指定生成的值包含多少个小数位。如果该参数被省略,默认值为 0。例如:Expr
28、ession Sample values r:.94:1.04 1, 0, 1, 0 r:.94:1.04:2 .95, 1.02, 1.01, .96 r:.94:1.04:4 3812, .9781, 1.2971, .9901 If more that one record is returned 如果一个以上的记录被返回有时,一个 SQL 语句将返回多条记录,即使只有一个值可以被 DataFactory 使用。此选项指定多个记录的返回应如何处理。目前有两种选择: Use the first record in the returned recordset Select a record
29、 at random from the set of returned records3、 Insert text from a file Folder from which to select files For each record DataFactory will randomly select a file from this folder and insert the files contents into the field. Include subfolders Select this option to have files in subfolders included in
30、 pool of files from which the file will be randomly selected 4、 Insert random characters Fixed number of characters Select this option to have a fixed number of characters inserted with each record.Random number of characters Select this option to have a random number of characters inserted with eac
31、h record.5、 Insert a string constant Constant ExpressionEnter the constant text expression that will be inserted with each record.6、 Build a composite field 二、Numeric Fields Decimal Places 它指定产生多少小数点。Width 这将生成有特定数目的数字。例如,值 9021,0005,0707 都有四宽度。Unique Set this option on to generate unique values. Ke
32、y Specifies a collection of fields that, as a whole, must be unique, but do not have to be individually unique. Auto Number 自动编号有些数据库支持每一个被插入的记录自动编号,MS Access 中这称为 - 自动编号,在 MS SQL Server 中这些被称为数字字段。自动编号属性是用来表明该字段的值是被数据库自动生成的,不应由 DataFactory 产生。插入记录后,这个字段的值会从数据库中被检索,以便它可以用来生成子表的外键值。Null Probability 空
33、概率决定这个字段生成空字段的概率。比如,值 20 将会导致大约 20%的行的值为空。Option This is the method DataFactory will use to generate the field value. The available options are Insert value from a data table Insert value from a SQL database table Sequential Values Random Values Constant Value Arithmetic Expression Arithmetic Expres
34、sions This allows a valid expression to be entered that will be evaluated at run time. This option supports the same tokens as the SQL option (F to include the value that was generated for another field and R to generate a random value). The syntax is the same as the SQL option but without the SQL k
35、eywords. The following operators and functions are supported: Oper Description Example * multiply f:salary * 2 / divide f:salary / 2 + add f:val + r:10:20 - subtract f:salary - 1000 power f:value 10 greater than f:salary 30000 sin sine sin(f:value) cos cosine cos(f:value) exp exponent exp(f:value) s
36、qrt square root sqrt(f:value) log logarithm log(f:value) tg tangent tg(f:value) asin arcsine asin(f:value) acos arccosine acos(f:value) atg arctangent atg(f:value) 三、Date /Time Fields Option This is the method DataFactory will use to generate the field value. The available options are Insert value f
37、rom a data table Insert value from a SQL database table Sequential Values Random Values Current System DateWeekdays and Weekend days 选择此选项,以产生工作日和周末日期Weekdays only Select this option to generate weekdays only Weekend days only 周末日期Select this option to generate weekend days only Unique Set this opti
38、on on to generate unique values. Key Specifies a collection of fields that, as a whole, must be unique, but do not have to be individually unique. Null Probability Determines how often a null value will be generated for this field. For example, a value of 20 would result in a null value in approxima
39、tely 20 percent of the rows. Format This is the format the date will have. This is provided for composite elements and for when you are writing the data to a flat fileSetting Standard FormatsThe standard format provides a variety of preformatted options. Below is a list of the available options with
40、 an example of each.Date: Time:blank: Field is blank blank: Field is blankShort date: 03/28/05 Short time: 14:18:52Medium date: 28-Mar-05 Medium time: 02:18:52 PMLong date: Monday, March 28, 2005 Long time: 02:18:52 PM Central Standard TimeSetting Custom FormatsThe custom format settings allows you
41、to generate the date/time fields using parameters. For example: Custom format: %m/%d/%Y %H:%M:%SGenerated date/time: 03/28/2005 14:18:52Below is a list of the available parameters.Parameter Definition%a Abbreviated weekday name%A Full weekday name%b Abbreviated month name%B Full month name%c Date an
42、d time representing appropriate locale%d Day of month as decimal number (01-31)%H Hour in 24-hour format (00-23)%I Hour in 12 hour format (01-12)%j Day of year as decimal number (001-366)%m Month as decimal number (01-12)%M Minute as decimal number (00-59)%p Current locales A.M./P.M indicator for 12
43、 hour clock%S Second as decimal number (00-59)%U Week of year as decimal number, with Sunday as first day of the week (00-53)%w Weekday as decimal number (0-6; Sunday is 0)%W Week of year as decimal number, with Monday as first day of the week (00-53)%x Date representation for current locale%X Time
44、representation for current locale%y Year without century, as decimal (00-99)%Y Year with century, as decimal number%z, %Z Either the time-zone name or the time zone abbreviation, depending on registry settings; no characters if time zone is unknown% Percent sign四、Blob FieldsThis option allows you to
45、 load a Binary Large Object (BLOB) when a script is executed.Use this Property. To.Insert a file from the following folderSelect a file from this folder and insert the files contents into the fieldInclude subfolders Have files in subfolders included in the pool of files from which the file is random
46、ly selectedNull Probability Determine how often a null value is generated for this field. For example, a value of 20 would result in a null value in approximately 20 percent of the rows.Note: Null probability is grayed out if the field does not allow nulls.Folder from which to select files For each
47、record DataFactory will randomly select a file from this folder and insert the files contents into the field. Include subfolders Select this option to have files in subfolders included in pool of files from which the file will be randomly selected Null Probability Determines how often a null value w
48、ill be generated for this field. For example, a value of 20 would result in a null value in approximately 20 percent of the rows.To set BLOB properties1. Click the desired Field node. 2. Click . 3. Navigate to and select the desired BLOB file folder.4. Click OK.五、Drag-and-Drop Property Replication 该
49、属性的复制功能,您可以复制一个字段的属性到一个或多个其他字段。这可以节省时间,如果你用大量的具有类似性质问题的字段。复制的字段的属性,只需将项目视图图标拖放到另一个字段。目标字段可以在任何项目视图(左窗格)或列表视图(右窗格中) 。您可以在列表视图突出显示多个字段,再复制字段的属性到多个字段。五、数据表 data tableDataFactory 数据表是包含文本,数字和日期值的二进制索引文件。您可以轻松地从数据库或分隔的文本文件数据创建自己的数据表。要创建一个数据表,单击工具栏上创建数据表按钮,然后选择 Import data from text file or Import data from database 来导入数据。1、 Import Data from Text FileThis option creates a data table from a specified text file. The text file must be for