The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Smalltalk Daily 04/20/10: Array Binding with Oracle and ObjectStudio

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Smalltalk Daily 04/20/10: Array Binding with Oracle and ObjectStudio Posted: Apr 20, 2010 8:16 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Smalltalk Daily 04/20/10: Array Binding with Oracle and ObjectStudio
Feed Title: Cincom Smalltalk Blog - Smalltalk with Rants
Feed URL: http://www.cincomsmalltalk.com/rssBlog/rssBlogView.xml
Feed Description: James Robertson comments on Cincom Smalltalk, the Smalltalk development community, and IT trends and issues in general.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Cincom Smalltalk Blog - Smalltalk with Rants

Advertisement

Today's Smalltalk Daily looks at using Array Binding for insertions and queries with Oracle and ObjectStudio 8. If you're looking for a particular topic, you can find it with the Media Search application on our site. Here's the script used in the screencast:


"Array binding and Array fetching example."

"Some databases allow client control over the number of rows that
 will be physically transferred between the server and the client in 
one logical bind or fetch. Using array binding and array 
fetching can greatly improve the performance of many applications 
by trading buffer space for time (network traffic)."


"The following Workspace examples will show the performance
 improvements when using array binding and array fetching in OS8."

"Logon to the Oracle Server."
ObjectStudio.OracleDatabase logOnServer: #'OracleDB' user: #'username' password: #'pwd' alias: #'OracleDB'.

"Get the Oracle database instance."
db := ObjectStudio.Database accessName: #'OracleDB'.

"Drop the test table if existed."
db execSql: 'DROP TABLE TESTTABLE'.

"Create a test table."
db execSql: 'CREATE TABLE TESTTABLE(
	NUMMER int ,
	BEMERKUNG varchar2 (30)
)'.

"Set the number of recrods being inserted."
loopCount := 1000.

"The SQL used to do inerst."
sql := 'INSERT INTO TESTTABLE VALUES (?, ?)'.

"Insert: not using array binding."
insertTime1 := [

	1 to: loopCount do: [ :i|
         db execSql: sql vars: (Array with: i with: 'test').
	].			
] millisecondsToRun.

"Print out the miliseconds spent."
('Insert without using array binding: ' + insertTime1) out.

"Insert: Using array binding."
insertTime2 := [
|bindArray numArray stringArray |
    numArray := OrderedCollection new.
    stringArray := OrderedCollection new.
	1 to: loopCount do: [ :i|
		numArray add: i.
		stringArray add: 'bla'.
	].			
	bindArray := OrderedCollection with: numArray with: stringArray.
    sql := 'INSERT INTO TESTTABLE VALUES (?, ?)'.
    db execSql: sql vars: bindArray.
] millisecondsToRun.

"Print out the miliseconds spent."
('Insert using array binding: ' + insertTime2) out.

"Set times to repeat."
loopCount := 1.

"Set the SQL to do the fetch."
sql := 'SELECT * from TESTTABLE'.

"Default value of arrayFetchSize is 1."
db setArrayFetchSizeTo: 1.

selectTime1 := [
1 to: loopCount do: [ :i|
        db execSql: sql.
    ].
] millisecondsToRun.

"Print out the miliseconds spent."
('Select with arrayFetchSize= 1: ' + selectTime1) out.	

"Set arrayFetchSize to be 100."	
db setArrayFetchSizeTo: 100.

selectTime2 := [
1 to: loopCount do: [ :i|
    db execSql: sql.
	]
] millisecondsToRun.

"Print out the miliseconds spent."
('Select with arrayFetchSize=100: ' + selectTime2) out.

"Set arrayFetchSize to be 500."	
db setArrayFetchSizeTo: 500.

selectTime3 := [
1 to: loopCount do: [ :i|
    db execSql: sql.
	]
] millisecondsToRun.

"Print out the miliseconds spent."
('Select with and arrayFetchSize=500: ' + selectTime3) out.

To watch, click on the viewer below:

If you have trouble viewing that directly, you can click here to download the video directly

You can also watch it on YouTube:

Technorati Tags: , , , ,

Read: Smalltalk Daily 04/20/10: Array Binding with Oracle and ObjectStudio

Topic: Agile Conferences: Look To No Epiphany Previous Topic   Next Topic Topic: Industry Misinterpretations 184: Across Smalltalks (AAC)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use