Monthly Archive for July, 2006

String Concatenation (Memory Buffer)

While working with a certain web application, I just found my self trapped on a string concatination problem. What I’m tryin’ to do is concatenate 2 strings and assigning the output to the first string. My code goes something like this:

PSEUDO CODE

var myString=”";

for(i=1;myQuery.recordCount;i++){
     myString = myString & myQuery.record[i];
}

note:
Let say myQuery is a SQL query which returns
all the fields and its value from a certain table

Looks simple huh? but the problem is, as the record count increases the performance decreases.
say myQuery returns 20 columns and 60,000 rows, using the code above will makes you wait forever. This kind of problem had never been totally solved until the .Net stringbuilder exist.
Since I am not using .Net, I have to find my own way to fix this problem.

What happen behind the code is that, the code creates a new myString object containing the result of the concatenation and discards the old myString. The value of myString is now then temporarily saved in a single memory buffer. So if the loop is repeated several times, the value of myString goes larger and for every 1 loop, the code retrieves that large data from a memory and then saves it again and again and again. And as the data inside the myString goes larger, the performance slows down.

I came with this idea wherein instead of saving the data in a single buffer, why not divide the data and saves it into different memory buffer, in that case, the size of the data in a single buffer will never be too large for it to slow down the performance of the system.

here’s the new code:


PSEUDO CODE

var myString=”";
var x=0;
var j=1;
var myString[1]=”",….myString[20];

for(i=1;i=20;i++){
     x=myQuery.recordCount*i/20;
     for(j;myQuery.recordCount;j++){
          myString[i]=myString[i] & myQuery.record[j];
          if(j==x){
               break;
          }
     }
}

myString = myString[1] & myStrinf[2]……..myString[20]

This code will divide the data into 20 parts and assign each data to 20 different variables.
Once the looping is done, all the data will be set into a single variable called myString.

Using these codes, it changed my waiting time from 15mins to less than a minute.

SQL Union All

I was working in this certain module last week wherein I will create a web app page that will generate monthly reports. Everything was fine and I manage to do it with an ease until the boss checks my work, On the report generated, there was a certain field column wherein NULL values are present, though some has a value, still it is impossible because that field is required in the form, and so the 1st problem occurs

In that module, what I did is I created a views in sql wherein it contains the computations of the data selected from a certain table, and I also added a field named “officerFld” which will contain an officer’s name selected from a certain field from another table.

I started to investigate the problem and found out that the officer’s name is stored in two different tables wherein I only selected from one of those tables. So I started searching for a way on how to select those officer’s name from the second table and insert it on the “officerFld” on the views that i’ve created, in that case, all the NULL values will be replaced by the officer’s name from the second table and all the officer’s name from the first table will still remain in the “officerFld” found on the views that i created.

Thanks to kiko(my older brother), who gave me the idea to use the UNION ALL command in sql. Well, I’m just starting to learn sql so don’t expect me to know all the commands. But now I’m starting to acquire knowledge so that’s what i did, i used the UNION ALL command in sql to combine the results of my two queries together and I used LEFT OUTER JOIN to combine it to my views.

Coldfusion

I work at a company where coldfusion is the main tool in web applications development. Though I am using ASP before I was hired, I still have to be focus on coldfusion so I have no choice but to learn it starting from the basics. First I decided to study the idea of how does coldfusion connects to the database, and I was amaze on how easy it is compare to other language. All you have to do is open the coldfusion administrator and and go to ODBC page and you are now ready to add a path to your database. See image below.

cfusion0
this is the ODBC page where you can choose what kind of database you will add

cfusion1
this is the create ODBC page where you will add your data source

cfusion2
this is the edit ODBC page where you can set and edit the properties of your data source

After you finished adding your data source, you can now add a coldfusion tag to your HTML to create your query. see code below.

  <CFQUERY NAME=”GetRecords” DATASOURCE=”YourDataSourceName”>
      SELECT lastName, firstName
      FROM TableName
      ORDER BY lastName, firstName
  </CFQUERY>

now to display the output, simply use the cfoutput tag. see code below.

   <CFOUTPUT QUERY=”GetRecords”>
      #GetRecords.CurrentRow#) #lastName#, #firstName#<BR>
   </CFOUTPUT>

# is equal to the % of ASP
GetRecords.CurrentRow - number of current record being displayed

sample output:

1) Abraham, Martin
2) Banks, Michelle
3) Jackson, Michael

see how easy and fast it is to access your database using coldfusion? much easy than ASP. But still ASP is the best for me. I don’t know if coldfusion has any limitations yet, I’m just starting to learn it though.

Lichtenstein inspired pop art!

Roy Lichtenstein inspired pop art! a cool digital art inspired by Roy Lichtenstein style using photoshop. some kind of like turning your picture into cartoons. It’s easy to do but requires a lot of patience. just visit melissaclifton.com for the tutorials. I’ve created my own lichtenstein inspired digital art, Juz check it out!


LICHTENSTEIN INSPIRED POP ART

onStart()

Finally, I got my own technical blog. Well I’m a novice in programming, I just recently got my first job as a software developer. I really want to be focus on .Net programming but unfortunately the company that hired me are using the old VB6 and coldfusion. But it’s ok, For now I’ll just let the current lead me to where it want me to be. I’ll just keep my self updated with the .Net technology.