08-02-2005 05:51 AM
Brosig
08-03-2005 11:11 AM
Brosig -
The limitation that I found when designing the MySQL schema was that in order to maintain constraints between tables the TestStand database logging feature needs to be able to get back the primary key(auto incremented number) for a record when created in order to use it as a foreign key in a second record in a different table. For example after creating and committing a record into the TestUUTs table, when immediately reading the primary key field, the value is not available so I cannot use it in the StepResult table.
I thought that I would just try it again, but now I am hitting issues with writing data to VARCHAR fields. The ODBC driver just does not behave as nicely for recordsets as it does for insert statements.
08-04-2005 12:53 AM
Hello Scott!
Thanks for your research.
08-04-2005 11:46 AM
02-07-2006 02:09 PM
05-22-2007 08:42 PM
05-23-2007 03:34 PM
Adam -
The TestStand Database Logging feature does not allow you to run a separate SQL command after executing the command for a statement(table), so I do not think that you can use an auto incrementing column for the tables. There is just no way to get it back in a generic way. One option that I tried is something similar to the Oracle schema where you call a store procedure to return a sequence ID for each record that you want to add.
So you would have to create the following sequence table in MySQL:
CREATE TABLE sequence (id INT NOT NULL);
INSERT INTO sequence VALUES (0);
Then create a stored procedure as shown below that will increment the sequence value and return it in a recordset:
CREATE PROCEDURE `getseqid`()
BEGIN
UPDATE sequence SET id=LAST_INSERT_ID(id+1);
SELECT LAST_INSERT_ID();
END
Then update the MySQL tables to use INT primary and foreign key values, so the TestStand MySQL SQL file to create all tables would have text like this:
CREATE TABLE UUT_RESULT
(
ID INT PRIMARY KEY,
...
)
~
CREATE TABLE STEP_RESULT
(
ID INT PRIMARY KEY,
UUT_RESULT INT NOT NULL,
...
)
~
...
Then update the schema primary and foreign key columns in the TestStand Database Options dialog box to be INT to match the table. For the primary key columns, you will have to set the Primary Key Type to "Get Value from Recordset" and set the Primary Key Command Text to "call getseqid()". This will call the stored procedure to determine the next value to use as the ID value.
Hope this helps...
05-23-2007 05:03 PM
05-25-2007 10:18 AM
Adam -
My choice of INT when I tested it was the wrong datatype if it defaults to a 2 byte number. We get and store the primary key value as a variant value, so whatever we are given from the database, we will use it as the foreign key later. The variant type support 4 byte and even 8 byte integers. Minimally the MySQL ODBC driver will support 4 byte which is 2G values, which should be sufficient.
For GUIDs, we rely on Microsoft functions to generate the unique GUID and we do not ask the database if the GUID already exists. My understanding is that the function will not generate a duplicate value across systems. If the logging feature attempts to log a record with a key that already exists, typically the database will fail the SQL statements being executed. In the case of the default process models, they will raise the error to the sequence and the execution will terminate. I would not expect this to happen.
05-25-2007 10:41 AM