Export new added row from global table to SQL database

Export new added row from global table to SQL database

farah_a
Not applicable
326 Views
9 Replies
Message 1 of 10

Export new added row from global table to SQL database

farah_a
Not applicable

Greeting everyone,

I have built a model in which I add rows and columns in a global table using process flow.

I want to export the added row simultaneously in my sql table, this means each time a row is added in my global table, it should be added at the same time in my database.

My question is how can i automatically export the data without having to do it manually from DBconnector ? what trigger is needed ?

i have basic knowledge in sql, which query can help me do that ?

Thank you for your help folks

0 Likes
Accepted solutions (1)
327 Views
9 Replies
Replies (9)
Message 2 of 10

tanner_p
Not applicable

Hi @Farah A,

To add a new column, I think you could execute SQL code like what's below:

ALTER TABLE MyTable
ADD NewColumn varchar(255);

You would just execute it at the same time the new column is created. I'm not entirely sure the best way to do this, though. It's just an idea.

As for automatically exporting all this data, you might look at this question or at the User Manual section entitled, "Excel Interface".

0 Likes
Message 3 of 10

farah_a
Not applicable

thanks for your answer. but i want it to add the data that are in my global table. i can do this by exporting it in my DBConnectors but i want it to be added each time there's a new value

0 Likes
Message 4 of 10

philboboADSK
Autodesk
Autodesk

No trigger is going to fire when you add a row to a global table. If you want to export after adding the row, then you need to adjust your code everywhere you add a row to add the row and then also export.

You could wrap those two operations together into a user command if you wanted.



Phil BoBo
Sr. Manager, Software Development
0 Likes
Message 5 of 10

farah_a
Not applicable

okay, i hva tried to put a command that can do that, add a row and export data in a custome code but i'm having this error and i dont know what does that mean ?

sql-code.pngerror.png

0 Likes
Message 6 of 10

philboboADSK
Autodesk
Autodesk

That error means exactly what it says:

Data type Database.DataType does not support property Integer.

You have to use one of the values available in Database.DataType. Database.DataType.Integer isn't in that list. Database.DataType.Int is. Depending on how your database is configured, you might need SmallInt, BigInt, or Numeric for that field.

Also, why are you calling con.disconnect() from that code when you aren't calling connect() from that code?



Phil BoBo
Sr. Manager, Software Development
0 Likes
Message 7 of 10

farah_a
Not applicable

@phil.bobo does not the command Database.Connection con = Database.Connection("DBConnector1"); do the connection with database ?

0 Likes
Message 8 of 10

braydn_t
Not applicable

@Farah A

That creates an instance of the Database object. You still need to call the connect method to establish a connection. There is an example here in the documentation:

https://docs.flexsim.com/en/20.0/Reference/CodingInFlexSim/FlexScriptAPIReference/Data/Database.Prep...

Message 9 of 10

benjamin_w2
Not applicable

Hi @Farah A,

Do you still need help with this?

0 Likes
Message 10 of 10

farah_a
Not applicable
Accepted solution

Thanks @Benjamin W2 for your consideration,this code worked well for me to write in MysqlDatabase :

Database.Connection con = Database.Connection("DBConnector1");

con.connect();

Database.PreparedStatement statement = con.prepareStatement("INSERT INTO Table1 (id) VALUES (:id )");

statement.bindParam("id", Table("Date DG")

[1], Database.DataType.Int);

statement.execute();

con.disconnect();

0 Likes