# Raw-SQL

**URL:** <https://forum.servoy.com/t/raw-sql/5416>\
**Category:** Classic Servoy\
**Created:** [January 31, 2006, 7:09pm UTC](https://forum.servoy.com/t/raw-sql/5416 "2006-01-31T19:09:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![tweetie](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@tweetie](https://forum.servoy.com/u/tweetie)\
**Post date:** [January 31, 2006, 7:09pm UTC](https://forum.servoy.com/t/raw-sql/5416/1 "2006-01-31T19:09:32Z")

</div>

Is there maximum amount of data you can put into the query?```  
var done = plugins.rawSQL.executeSQL(“blah”,“blah\_table”,query)

```The

```

DELETE FROM test\_child;  
INSERT INTO test\_child ( id, blah) VALUES ( 1,‘QUION’);  
INSERT INTO test\_child ( id, blah) VALUES ( 2,‘SMORGASBROTT’);  
etc  
etc  
etc  
let say a 500 INSERTS…

```auto

Servoy freezes up...and I need to go Ctrl+Alt+Del to stop the mess.

With smaller sql-statements it works like a charm....

Servoy Developer
Version R2 2.2.3-build 335
Java version 1.5.0_06-b05 (Windows 2000)
```

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [February 6, 2006, 9:17am UTC](https://forum.servoy.com/t/raw-sql/5416/2 "2006-02-06T09:17:13Z")

</div>

Hi, I have used the RawSQL plugin to insert 35,000 rows in one go.  
You just collect all the INSERTS on separated lines into one string. Remember to add “;” at the end of each statement. Works like a dream.

---

<div class="post-metadata">

**Author:** ![tweetie](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@tweetie](https://forum.servoy.com/u/tweetie)\
**Post date:** [February 6, 2006, 9:38am UTC](https://forum.servoy.com/t/raw-sql/5416/3 "2006-02-06T09:38:39Z")

</div>

> swingman:  
> Hi, I have used the RawSQL plugin to insert 35,000 rows in one go.  
> You just collect all the INSERTS on separated lines into one string. Remember to add “;” at the end of each statement. Works like a dream.

Hi Swingman  
Thankx for the info. Can you show an example…is it different from the query mentioned above? Becoz with the query mentioned above I couldn’t get in 1200 rows…without Servoy stopping all activities…

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [February 7, 2006, 6:42am UTC](https://forum.servoy.com/t/raw-sql/5416/4 "2006-02-07T06:42:46Z")

</div>

Hi tweetie,

I’m doing pretty much the same as you, just more fields and more records – in batches rather than one by one. The only difference I can think of is that I use DB-generated keys, so I don’t have to insert a PK.

Are you checking to see if you get any error messages back from the rawSQL plugin?

Also, capture the insert statements as text and execute them outside Servoy, some tools like Aqua Data Studio (Any SQL database) or PGAdmin (Postgresql only) will tell you much more if there is something wrong with your SQL statements. You will be able to work out if this is a Servoy bug or a database problem.

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [February 7, 2006, 10:19am UTC](https://forum.servoy.com/t/raw-sql/5416/5 "2006-02-07T10:19:58Z")

</div>

> tweetie:
> 
> ```auto
> DELETE FROM test_child;[code]
> 
> ```

[/quote]

Hi, I just added a delete to my script and Servoy falls over on the 4th one…  
Either I’m doing something stupid or there is a bug.

Try deleting manually and use the plugin only to add records… and see if it works.

> ```auto
> 
> ```

---

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [February 7, 2006, 12:26pm UTC](https://forum.servoy.com/t/raw-sql/5416/6 "2006-02-07T12:26:16Z")

</div>

do you use the **;** in your query?

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [February 7, 2006, 3:38pm UTC](https://forum.servoy.com/t/raw-sql/5416/7 "2006-02-07T15:38:34Z")

</div>

; is a end-of-line in SQL… should do no harm to put it on the end of a statement.

---

<div class="post-metadata">

**Author:** ![tweetie](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@tweetie](https://forum.servoy.com/u/tweetie)\
**Post date:** [February 7, 2006, 4:42pm UTC](https://forum.servoy.com/t/raw-sql/5416/8 "2006-02-07T16:42:57Z")

</div>

> swingman:  
> Hi tweetie,
> 
> I’m doing pretty much the same as you, just more fields and more records – in batches rather than one by one.

What do you mean in batches?

> The only difference I can think of is that I use DB-generated keys, so I don’t have to insert a PK.

Gonna try that

> Are you checking to see if you get any error messages back from the rawSQL plugin?

I just dont get that far…Servoy freezes up completely and the method is not finished, so I do get an errorcode

> Also, capture the insert statements as text and execute them outside Servoy, some tools like Aqua Data Studio (Any SQL database) or PGAdmin (Postgresql only) will tell you much more if there is something wrong with your SQL statements.You will be able to work out if this is a Servoy bug or a database problem.

Did that with Sybase Central’s INteractive SQL…worked like a charm

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [February 7, 2006, 4:51pm UTC](https://forum.servoy.com/t/raw-sql/5416/9 "2006-02-07T16:51:01Z")

</div>

There is a possibility of locking yourself when a transaction is active. Do you use transactions when doing your inserts?

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [February 7, 2006, 5:30pm UTC](https://forum.servoy.com/t/raw-sql/5416/10 "2006-02-07T17:30:29Z")

</div>

> tweetie:  
> What do you mean in batches?

I feed 100 inserts at a time to the rawSQL plugin…

---

<div class="post-metadata">

**Author:** ![tweetie](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@tweetie](https://forum.servoy.com/u/tweetie)\
**Post date:** [February 26, 2006, 4:07pm UTC](https://forum.servoy.com/t/raw-sql/5416/11 "2006-02-26T16:07:17Z")

</div>

Still having troubles with this plugin. Servoy freezes up completely when I do this:

```auto
if (arguments[0]){
	var query = "DELETE FROM adres WHERE (adres='' OR adres is NULL) AND client_id="+arguments[0]
	var done = plugins.rawSQL.executeSQL("assyst","adres",query)
	if (done){
		plugins.rawSQL.flushAllClientsCache("assyst","adres")
	} else {
		plugins.dialogs.showErrorDialog('Error', 'SQL error: '+plugins.rawSQL.getExceptionMsg(), 'Ok')
	}
}

```

The query has also been tested in Sybase Central…and it works

Servoy Developer  
Version R2 2.2.4-build 336  
Java version 1.5.0\_06-b05 (Windows 2000)

---

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [February 26, 2006, 5:40pm UTC](https://forum.servoy.com/t/raw-sql/5416/12 "2006-02-26T17:40:37Z")

</div>

Any error message in your console?

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [February 26, 2006, 7:09pm UTC](https://forum.servoy.com/t/raw-sql/5416/13 "2006-02-26T19:09:05Z")

</div>

It could be you ran into a lock. One session blocks your raw sql statements and your method waits for an answer of the (blocked) statement. Check your database if you have a lock while Servoy “hangs”.

What database are you using? Do you have a transaction running while it happens?

---

<div class="post-metadata">

**Author:** ![tweetie](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@tweetie](https://forum.servoy.com/u/tweetie)\
**Post date:** [February 27, 2006, 1:11pm UTC](https://forum.servoy.com/t/raw-sql/5416/14 "2006-02-27T13:11:13Z")

</div>

> patrick:  
> It could be you ran into a lock. One session blocks your raw sql statements and your method waits for an answer of the (blocked) statement. Check your database if you have a lock while Servoy “hangs”.
> 
> What database are you using? Do you have a transaction running while it happens?

I am the only user…the row(s) I am trying to delete don’t exist long enough to be locked be anything or any-one. I am using sybase. But I will look into it when it hangs…I now use the Servoy-way to search and delete for the time beeing.

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [February 27, 2006, 2:11pm UTC](https://forum.servoy.com/t/raw-sql/5416/15 "2006-02-27T14:11:55Z")

</div>

Hi, I have found that sometimes an operation takes a long time, it kind of hangs for a while – like 5-10 minutes. I haven’t found a pattern yet, so I don’t know if I’m doing something stupid, my server has a problem or it is Servoy’s fault.

---

<div class="post-metadata">

**Author:** ![tweetie](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@tweetie](https://forum.servoy.com/u/tweetie)\
**Post date:** [February 27, 2006, 2:58pm UTC](https://forum.servoy.com/t/raw-sql/5416/16 "2006-02-27T14:58:10Z")

</div>

> IT2BE:  
> Any error message in your console?

Nope…everything freezes up, including the console

---

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [February 27, 2006, 3:05pm UTC](https://forum.servoy.com/t/raw-sql/5416/17 "2006-02-27T15:05:08Z")

</div>

When I am correct in what I am thinking the plugin is a 1:1 implementation of Java stuff. Having that said I suspect it is the driver and not the plugin. Are you using the latest driver?

---

<div class="post-metadata">

**Author:** ![tweetie](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@tweetie](https://forum.servoy.com/u/tweetie)\
**Post date:** [February 27, 2006, 3:16pm UTC](https://forum.servoy.com/t/raw-sql/5416/18 "2006-02-27T15:16:44Z")

</div>

> patrick:  
> It could be you ran into a lock. One session blocks your raw sql statements and your method waits for an answer of the (blocked) statement. Check your database if you have a lock while Servoy “hangs”.
> 
> What database are you using? Do you have a transaction running while it happens?

I stand corrected, there seems to be locks. See attachment

> IT2BE:  
> When I am correct in what I am thinking the plugin is a 1:1 implementation of Java stuff. Having that said I suspect it is the driver and not the plugin. Are you using the latest driver?

You lost me here…what driver?

 ![locks.gif](https://canada1.discourse-cdn.com/flex010/uploads/servoy/original/2X/c/ce94c56b34e0d081dc6f1fdc238632321b687c42.gif)

---

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [February 27, 2006, 3:22pm UTC](https://forum.servoy.com/t/raw-sql/5416/19 "2006-02-27T15:22:45Z")

</div>

I think you already have your answer to what caused the issue but I was talking about your database driver… Working this way you are working on the database without any ‘help from Servoy’. That’s also the tricky part. You need to be aware of database specific stuff in some cases and be aware locking stuff in this particular case ![:)]( "Smile")

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [February 27, 2006, 3:31pm UTC](https://forum.servoy.com/t/raw-sql/5416/20 "2006-02-27T15:31:51Z")

</div>

The problem about locking here is this:

if the connection you are using locks a record for whatever reason (usually due to a transaction) and you then fire a sql to such a locked record, you are “dead”. The reason for this is that the SQL plugin uses its own connection for its stuff, so the database correctly refuses any changes to those records until the lock is released.

Then you are dead-locked. Your method fires a statement to a record that was locked by your method before and waits until that is finished. That can take a while ![:wink:]( "Wink")

I have run into the same situation several times and already discussed this with Jan Blok. I think the behaviour would probably improve if the same connection was used. Then the database will allow any statement on locked records, because the lock comes from the same session as the statement is using. So maybe we should emphasize this wish and move this to the feature request section…

[Next page](https://forum.servoy.com/t/raw-sql/5416.md?page=2)
