Red Gate forums :: View topic - Custom Generator string return val limitations?
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SQL Data Generator 1
SQL Data Generator 1 forum

Custom Generator string return val limitations?

Search in SQL Data Generator 1 forum
Post new topic   Reply to topic
Jump to:  
Author Message
bretlowery



Joined: 09 Oct 2010
Posts: 10

PostPosted: Sat Oct 09, 2010 2:51 pm    Post subject: Custom Generator string return val limitations? Reply with quote

Hi, I'm doing a POC of Data Generator 1 against a SQL Server 2008 SP1 database. I have successfully created and used the custom class generator listed below, but it only appears as an option for NVARCHAR columns, not VARCHAR columns. How can I get this generator to appear as an option on my VARCHAR columns? Are there other type or length limitations to returns types used in custom generators?

Thanks!

[Generator(typeof(String), "Generic", "Company Emails", "In a.b@nowhere.com format")]
public class EmailGenerator: IGenerator
{

protected List<string> testdata = new List<string>();

public EmailGenerator(GeneratorParameters parameters)
{
testdata.Add("marge.n.overror@nowhere.com");
testdata.Add("heywood.ubuzzoff@nowhere.com");
testdata.Add("heywood.ustopitt@nowhere.com");
testdata.Add("heywood.ulevmealohn@nowhere.com");
testdata.Add("les.izmore@nowhere.com");
testdata.Add("itwerks.onanoff@nowhere.com");
}

public System.Collections.IEnumerator GetEnumerator(GenerationSession session)
{
Random rnd = new Random(DateTime.Now.Millisecond);
while (true)
{
yield return testdata[rnd.Next(0, testdata.Count)];
}
}
}
Back to top
View user's profile Send private message
james.billings



Joined: 16 Jun 2010
Posts: 1121
Location: My desk.

PostPosted: Mon Oct 11, 2010 3:02 pm    Post subject: Reply with quote

Thanks for your post.

I've created a generator myself based on your class, and got it to appear for both nvarchar and varchar columns.

Could you perhaps post your config file, or, if you prefer, email it to support@red-gate.com quoting F0040000 in the subject line?

Thanks!
Back to top
View user's profile Send private message
bretlowery



Joined: 09 Oct 2010
Posts: 10

PostPosted: Tue Oct 12, 2010 2:35 pm    Post subject: Reply with quote

I can send config file. Can you tell me which one you need?

Interestingly, the problem doesn't appear to be related to the data type, data length, nullability, or ordinal position of the column in the tables. I see my custom generator on most tables in my database, but not all. Weird.

I tried specifying a new "category" of generators by changing this:

[Generator(typeof(String), "Generic", "Company Emails", "In a.b@nowhere.com format")]

to:

[Generator(typeof(String), "Interclick", "Company Emails", "In a.b@nowhere.com format")]

which gave me the same symptoms on the same tables. I also reinstalled Data Generator, and created a brand new project on the same database, and have the same problem on the same tables.

Really weird.

I can send the entire generator .cs file to you if you'd like.
Back to top
View user's profile Send private message
james.billings



Joined: 16 Jun 2010
Posts: 1121
Location: My desk.

PostPosted: Tue Oct 12, 2010 2:39 pm    Post subject: Reply with quote

I don't think the .cs file will be the problem. Once you have your DLL in place in the Generators folder, you need a config file to then help it show up in Data Generator. This will go in the "config" subfolder. For instance, when testing your class, I created "CompanyEmail.xml" with the following contents:


<?xml version="1.0" encoding="iso-8859-1"?>
<generators>
<generator /* Specify the class. */
type="EmailGenerator"
name="Company Emails"
description="In a.b@nowhere.com format"
category="Generic">

/* Specify the columns that match, and their score. */
<matches field="*" score="50"/>


/* Define the data types for which the generator is valid. */
<type type="string"/>
</generator>
Back to top
View user's profile Send private message
bretlowery



Joined: 09 Oct 2010
Posts: 10

PostPosted: Wed Oct 13, 2010 3:07 pm    Post subject: Reply with quote

Tried it, and it did not fix the problem. I've also tried reinstalling Data Generator, renaming the problematic table, the column in the table, and dropping then recreating my database; nothing worked. I've also checked my rights to the Data Generator folder and subfolders and I have full R/W access.

Again, on some columns in other tables with or without the same datatype and length, it worked both with and without the xml file.

I also modified my .sqlgen file by hand, copying the custom generator from a different table and column where it worked correctly, and pasting the generator block in the problematic column's generator tag. I was able to save and load the project successfully, but it still had the same problem, and after I saved the project again it overwrote my sqlgen file change.

I'm stumped.
Back to top
View user's profile Send private message
james.billings



Joined: 16 Jun 2010
Posts: 1121
Location: My desk.

PostPosted: Wed Oct 13, 2010 3:13 pm    Post subject: Reply with quote

Definitely a bit strange.

Is it possible for you to send over the database to us so we can test it here? You can mail it to support@red-gate.com quoting F0040000 in the subject line, along with details of which tables/columns are causing the problem (or include your project).

If could also include the xml config file and DLL it would be great, just in case I built mine slightly differently to yourself.
Back to top
View user's profile Send private message
bretlowery



Joined: 09 Oct 2010
Posts: 10

PostPosted: Wed Oct 13, 2010 3:26 pm    Post subject: Reply with quote

Stumped no longer; I figured it out. DataGenerator will not allow me to create a custom string generator on a varchar or nvarchar column if there is a unique index on the column. Once I removed the unique index, the custom generator appeared in the drop-down.

For my purposes, my custom generator will generate unique values as it's enumerated. Is there a way that this restraint can be removed?

Thanks for the support!
Back to top
View user's profile Send private message
james.billings



Joined: 16 Jun 2010
Posts: 1121
Location: My desk.

PostPosted: Wed Oct 13, 2010 3:38 pm    Post subject: Reply with quote

That makes sense. You'll need to include the IUniqueable interface and implement it, then your generator will show.

Obviously if the Index is only including that column, it will probably fail due to the values not being... unique Smile

See below for example:



using System;
using System.Collections.Generic;
using System.Text;
using RedGate.SQLDataGenerator.Engine;
using RedGate.SQLDataGenerator.Engine.Generators;
using RedGate.SQLDataGenerator.Engine.Generators.Static;

namespace CompanyEmailGenerator
{
[Generator(typeof(String), "Generic", "Company Emails", "In a.b@nowhere.com format")]
public class EmailGenerator : IGenerator, IUniqueableGenerator
{

protected List<string> testdata = new List<string>();
bool m_Unique;

public EmailGenerator(GeneratorParameters parameters)
{
testdata.Add("marge.n.overror@nowhere.com");
testdata.Add("heywood.ubuzzoff@nowhere.com");
testdata.Add("heywood.ustopitt@nowhere.com");
testdata.Add("heywood.ulevmealohn@nowhere.com");
testdata.Add("les.izmore@nowhere.com");
testdata.Add("itwerks.onanoff@nowhere.com");
}

public System.Collections.IEnumerator GetEnumerator(GenerationSession session)
{
Random rnd = new Random(DateTime.Now.Millisecond);
while (true)
{
yield return testdata[rnd.Next(0, testdata.Count)];
}
}

public bool Unique
{
get { return m_Unique; }
set { m_Unique = value; }
}
}
}
Back to top
View user's profile Send private message
bretlowery



Joined: 09 Oct 2010
Posts: 10

PostPosted: Thu Oct 14, 2010 7:41 pm    Post subject: Reply with quote

Got it, thx. Pls close.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group