I need to create records via SQL INSERTS

Questions and answers regarding general SQL and backend databases

I need to create records via SQL INSERTS

Postby elmono_acosta » Thu Jun 17, 2004 11:58 am

Is it possible to setup a string with an sql INSERT command so I can create record in my database this way ?

Some times when you need to create records in a 3 or even 4 way relationship, it is much easier with sql rather than with the standard method with servoy.

If the answare is YES, HOW ??????
Thanks.
elmono_acosta
 
Posts: 41
Joined: Thu Jun 17, 2004 11:52 am

Postby pbakker » Thu Jun 17, 2004 12:19 pm

You could do it by making a stored procedure in your database, to which you pass your insert statement, then the SP evaluates your string and executes it.

But, this insert will not be reflected in Servoy Client/Developer, untill you restart it.

I'm sure some other people on the forum will tell you it's not so hard to do the same through Servoy :D
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Postby bcusick » Thu Jun 17, 2004 7:12 pm

You cannot execute "raw" SQL statements (except for SELECT) in Servoy. The reason is because of client data consistency. If you did a delete or insert of tens or hundreds of records - how would Servoy "know" what records were affected? Answer - it wouldn't - so you could wind up in a situation where a client was looking at invalid data.

Instead - use a stored procedure to insert records or you can also use a loop in Servoy and add the records that way as well.

Hope this helps,

Bob Cusick
bcusick
 
Posts: 1255
Joined: Wed Apr 23, 2003 11:27 pm
Location: Thousand Oaks, CA USA

Postby r.rios » Fri Jun 18, 2004 5:45 pm

You could use a plugin to do an insert. But, like Bob said, Servoy would not be aware of the changes and could mean chaos.

I'm using a plugin to do a special insert into a table under special circumstances, but this is not recommended if not necessary.
Ronnie
r.rios
 
Posts: 58
Joined: Mon Dec 01, 2003 3:59 am

Postby elmono_acosta » Fri Jun 18, 2004 9:10 pm

OK.
What about if I use the plug in, and every time servoy wants to read data from the database I use a method that does:

//flushes the client data cache for recordIndex -1
//in the related foundset
//-1 for all data

databaseManager.refreshRecordFromDatabase(order_to_orderdetails,-1);
elmono_acosta
 
Posts: 41
Joined: Thu Jun 17, 2004 11:52 am

Postby r.rios » Sun Jun 20, 2004 11:08 pm

I'm not sure. It could work, maybe one of the Servoy kids can help answer that. Never the less, I wouldn't recommend intense use of this method.
Ronnie
r.rios
 
Posts: 58
Joined: Mon Dec 01, 2003 3:59 am

Postby Jan Aleman » Thu Jun 24, 2004 2:16 pm

Invaliditing cache can have enormous performance impact, imagine what would happen if you have 1000 users of your solution and you keep invaliditing theire entire cache all the time.

Why don't you simply create a form on the table you want to insert to and create new records through that? It doesn't matter at all how many relations away it is, you can address it directly. Aditionally that is also easier to code than INSERT statements and broadcasting and caching remains accurate.
Jan Aleman
Servoy
Jan Aleman
 
Posts: 2083
Joined: Wed Apr 23, 2003 9:49 pm
Location: Planet Earth


Return to SQL Databases

Who is online

Users browsing this forum: No registered users and 24 guests