Monday, August 07, 2006

IE Bug Using document.getElementById()

If you are using either document.getElementById() or prototype's $() and you have an element in your page with it's name that is the same as the id of an element that comes after it, DON'T DO IT!!!

IE treats the id and name attributes of elements equally when using document.getElementById().

For an example, use the following HTML code.


<html>
<body>
name: testMe
<input type="text" name="testMe" value="First Element" /><br />
name: dontTestMe id: testMe
<input type="text" name="dontTestMe" id="testMe" value="Second Element" />
<br />
<input type="button" onclick="alert(document.getElementById('testMe').value);" value="Click me to see what happens." " />
</body>
</html>


Working Example


name: testMe


name: dontTestMe id: testMe



Friday, May 26, 2006

Security Warning on MSDN



I got this warning when trying to go to MSDN from a search.

How comical is this!?

Tuesday, May 02, 2006

SQL index tip

This where clause can be made more simple and avoid unnecessary formatting by Oracle if you use the default Oracle format for the date test. Sometimes function calls will cause Oracle to disregard the index.

This:
update rad.dcd10dm
...
where dep > to_date('03/20/2006', 'MM/DD/YYYY');


Can be coded like this:
update rad.dcd10dm
...
where dep > '20-mar-06';

Wednesday, April 26, 2006

Oracle Tuning

For most efficient access, the order that tables are specified can make a difference. The optimiser will re-order table access based on the indexes available. If access paths on two tables seem equally efficient, Oracle will use the order of tables specified in the FROM clause to determine the execution path.
The rule is to place the table that reduces the number of returned rows by the largest factor last. This table tends to be the one that has most WHERE conditions reducing the data, or it is the smallest table. If in doubt, consult the DBA team.
Just to remind you that this order of tables is important only if you are using Rule Based Optimizer. If that is the case, then table with fewer rows should be listed LAST in the FROM clause (because that should be the driving table, and parser processes table names from right to left).


2.5 WHERE Clause
The bulk of SQL performance tuning relates to the careful specification of the WHERE clause. Each clause within the WHERE clause can be executed with varying degrees of efficiency. The efficiency of a particular WHERE clause is a function of the size of the table, and the indexes that are available on the selecting column(s).
2.5.1 Access Paths and Indexes
To obtain a row from a given table in the database, Oracle uses an access path. An access path is a mechanism of obtaining particular rows. A set of access paths for all tables involved in a query and the internal Oracle operations that join the results from the access paths form a complete execution plan.
Oracle supports many different access paths, of which at least one is available for every row required for each table used within a query. The following table shows the types of access paths supported by Oracle, where ranked number one is the most efficient and ranked 15 is the least efficient. Oracle uses the relative efficiencies in this table as part of the process of determining cost for a particular execution plan..

Rank Condition
1 Single row by ROWID
2 Single row by cluster join (only for clustered table)
3 Single row by hash cluster key with unique or primary key (only for hash clusters)
4 Single row by unique or primary key (where unique index exists)
5 cluster join (for cluster tables)
6 Hash cluster key (for cluster columns)
7 Indexed cluster key (for clustered columns)
8 Composite Index
9 Single column indexes
10 Bounded range searches
11 Unbounded range searches on indexes columns
12 Sort-merge join (join of non-indexed columns)
13 MAX or MIN of indexed column (where these group functions appear in the column list of the SQL statement.
14 ORDER BY on indexed columns
15 Full table scan. This access path is always available.
An index is an additional database structure that is manually created but automatically maintained by Oracle. One or more columns in a single table may be included in a single indexed, and there may be many indexes for a particular table.
An index allows rapid access to particular rows in a table when a WHERE clause selects
* all of the columns referenced by a particular index
* the leading columns of an index created over multiple columns.
Unless an index exists on columns used in the WHERE clause, access paths that use indexes are not available.
Cluster and hash indexes are characteristics of the way that tables are physically built in the database. As we can see from the table listed above that indexes and clustering make the most efficient access paths available to Oracle.
Accesses to non indexed columns in tables can only be made via a full table scan. For large tables, a full table scan will take a long time and is to be avoided. If the application needs to locate records in a large table by a non indexed column, seek advice from the DBA team.

3 Summary
This section summarises the following good practices which application developers should bear in mind when developing SQL scripts:
* Table Aliases - always use table aliases when more than one table is involved in a query. The advantages of this method are to prevent future syntax errors when ambiguously named columns is added to table.The SQL statement is more readable.
* Sequencing of WHERE clause conditions - Note that non-index WHERE clause conditions are evaluated one by one after retrieving the rows. The AND statements are evaluated bottom-up, and the OR statements are evaluated top-down. Always place complex AND conditions in the beginning and placing complex OR conditions at the end.
* Reduce the number of trips to the database - Every time a SQL is executed the statements are parsed, indexes are evaluated, variables are bound, and in a client-server environment, SQL and results are transferred over the network. In order to maintain efficiency developers should minimises the number of statements executed.
* WHERE vs HAVING - HAVING filters the groups after the rows have been fetched, sorted and grouped. WHERE filters the rows when they are fetched. Therefore, the WHERE statement will reduce the overheads involved in reading the data blocks and sorting. This in turn improves the performance.
* EXISTS in place of DISTINCT - EXISTS does not result in sorting and it is more efficient when an index is available. DISTINCT is always sorts the results and eliminates the duplicates.
* NOT EXISTS in place of NOT IN - NOT IN with a sub-query results in an internal sort. Replacing NOT IN (sub-query) with NOT EXISTS (co-related sub-query) may improve performance. Use this method ONLY WHEN an index is available for co-related sub-query.
* Using Indexes - Using indexes improves the performance only when the number of records to be retrieved are about 20% of total records in the table. To make the indexes available always avoid using calculations on indexed columns, and indexed_column <> value or using indexed_column IS NULL statements.

Tuesday, April 18, 2006

Data Access using ADO.NET Objects

prepared by John Papproth
on June 29th, 2005

ADO.NET is a disconnected data access model.
The model contains several classes that are found in the System.Data namespace.

There are two mirrored class groups in Visual Studio.NET 2003:
SQL prefixed classes (SQLConnection, SQLDataAdapter) are especially tuned for a Microsoft SQL Server Environment.
OleDb prefixed classes (OleDbConnection, OleDbDataAdapter) are intended for non SQL Server Environments such as Oracle, DB2, and Microsoft Access.

The following example uses Microsoft Access, the OleDb ADO.NET objects, and Visual Basic.NET to create a simple form driven update.

Example:
1. Create the data base and tables.
2. Create the form.
3. Create the ADO.NET class references.
4. Write code to instantiate the classes.

1. Create the data base and tables.
Create an Access Database.
Create a Table within the Access Database.

2. Create the form.
Create one label and textbox pair for each column in your table.

3. Create the ADO.NET class references.
Private cn As OleDb.OleDbConnection
Private da As OleDb.OleDbDataAdapter
Private ds As DataSet
Private dt As DataTable


4. Write code to instantiate the classes.

Create the connection
cn = New OleDb.OleDbConnection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & _
Application.StartupPath & "\YourDatabaseNameHere.mdb"


Create a new adapter, and set the connection in the command objects
(Replace the Select * with your Column Names)
da = New OleDb.OleDbDataAdapter("Select * from YourTableNameHere", cn)
da.SelectCommand.Connection = cn


Create an empty dataset
ds = New DataSet

Fill the dataset
da.Fill(ds, "YourTableNameHere")

Create the data table
dt = ds.Tables("YourTableNameHere")

Bind the fields to the data table

Binding a combo box control:
cboComboBox.DataSource = dt
cboComboBox.DisplayMember = "YourColumnNameHere"


Binding a text box control:
txtTextBox.DataBindings.Add("Text", dt, "YourColumnNameHere")