Oracle SQL – Return value regardless of record existance

Here’s the situation:

You want to query the status of a member and would always want to return result for your application regardless if it exists or not.

Despite having two queries to do this, we can do it in just one query. In my case, it’s due to my program structure and multiple database connectivity that do not allow me to make multiple queries and checking here and there yada yada to come to the conclusion that, the member doesn’t exists in the database.

Table: member

ID Name Country Status
111 Evan Singapore Active
222 Tanny Malaysia Active
333 Dennis Indonesia Inactive

Here’s what we can do

SELECT status FROM member WHERE id = ’444′ UNION SELECT ‘NOT EXISTS’ FROM dual WHERE NOT EXISTS(SELECT 1 FROM member WHERE id = ’444′ )

or you can further simplify it into one query rather than using UNION

SELECT NVL( (SELECT status FROM member WHERE item_id = ’444′ ),’NOT EXISTS’ ) FROM dual

Result:

Status
NOT EXISTS

Discussion:

The major advantage of doing so is that you can always be assured that the connection to your database is OK and the query result is OK as well. You can be assured that you can always get your result (and return some message if there isn’t), eliminating any other failing factors (db connection problem yada yada yada, of course you need to write your query properly)

Now, if there’s isn’t any result returned, something must have gone wrong with your database!

Alternatively, you can always structure your coding properly, include try and catch exception procedure as well.


Read More

Pinpoint your photo location with GeoPress

I found one useful plugin that’s make blogging about photos more meaningful/informative lately. It’s called GeoPress.

We can now easily pinpoint the location where we took photo of with this plugin. For example, I’m now writing this blog entry from my office. And, here’s goes my current location.

You can use three kind of mapping services. Namely, Google, Yahoo or Microsoft. It’s quite handy and easy to use.

Now, you can satisfy your visitors better. Time to change, Digi WordPress, always the smarter choice. :D

Read More

Lesson 101 for SQL Query in VB

There are basically more than one way of doing things in building the query for execution. First is you dump everything into the query string. Things will go wrong when the variables you passing in contain sensitive character like single quote and so on. Single quote will call it an end to the expression prematurely and causing SQL command error. Here comes the first, unsafe, direct way of doing things.

Dim con As OleDbConnection = New OleDbConnection(“connection string bla bla”)

Dim str As String = “SELECT * FROM admin WHERE id = ‘”+ idstr+”‘ AND password = ‘” + passwordstr +”‘ “

Dim cmd As OleDbCommand = New OleDbCommand(str, con)
Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim ds As DataSet = New DataSet
da.Fill(ds, “Record”)
con.Close()

The second way of doing it is to build the query in separate parts. The query string will look like…

Read More

Computer Graphics Project

cg.JPG

Download the EXE!!!

Another fantastic job by one of my friendĀ 

Read More

Hugo Multimedia Explorer

Hugo Multimedia Explorer lets you browse thru the drives in your computer and has the ability to playback mp3,wav,avi,mpeg,mpg and viewing jpg and png. It has special music playback ability in handling pop-up music player. More features awaits you when you start it!

aaa.JPG

FULL VERSION NOW AVAILABLE!!! GET IT NOW FOR ABSOLUTELY FREEE!!!
Please make sure that you have JRE and JMF installed before running the program. If you have difficulties running the program, please do tell me, i would be glad to help you out~! :D

More stuff after the jump!

Read More