Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Thursday, March 27, 2008

ASP VBScript Database Accessor Class

I've got some limitations with a web server I've been working with. It doesn't have support for .net assemblies, so I can't write web applications in Visual Studio 2005. This leads me to think of creative ways to handle functionality.

Anyways, I came up with an idea of creating a class in VBScript (ASP), where I could send post data to a script on the server that would in-turn access the database file and do what it needs to do. I took it one step further, where all talk between client and server is XML. So the client sends "mock" SQL in the from of XML and in turn receives a response in XML saying if it worked, or returning data from the database.

I'm releasing the code under the Lesser GPL here (revised 04/09/2008):
http://www.netnobi.com/software/lgplaccessdatabase.php

I fixed quite a few errors that I ran into while using the class recently. I also added a few features to the select type xml that can processed by the class.

Saturday, February 16, 2008

C# .NET Programming Tip: Keeping A History With Properties

The program I am writing at work's primary functionality is a checklist. One of the requested features is the ability to record what actions a user performs on the checklist. So there needs to be some additional code that updates a history table whenever a user makes any changes to the checklist.

Let's define when a history event should fire off:
When the user makes a new checklist.
When the user updates any property of the checklist.
When a user archives a checklist (eg: discard in so many works).

Making a history entry when the user makes a new checklist or archives a checklist is easy. There would generally be only one function for each, so just before or after adding or archiving the checklist from the database, the history process is called.

What about when the user updates a single field in a checklist? It is important to track those changes, because a single little change is generally the most important (he said, she said situation).

In my program checklistprocessor, checklist, checklistitem, history, and database are all separate objects. So what would be an easy way to update each property individually and also record the before/after state in a history entry?

Use properties!

Here is an example of one such property:


class CheckListItem
{
private int id;
private int checkListId; //foreign key to CheckList
private string notes;
...

//will hold a reference that is received from a calling object
private Database dbConnection;

public string Notes
{
get { return this.notes; }
set
{
//create history entry for this change
History.add(id, checkListId, this.notes, value);

//update instance variable
this.notes = value;

//update database with new value
dbConnection.queryNoResult("UPDATE ... WHERE... ;")
}
}

...

Remember that C# is case sensitive. That means we can have a Notes property and a notes class variable. It makes things a lot simpler naming wise and is, from what I have read, an unofficial standard practice.

As you can see from the code, all the checklist has to do to update a checklistitem variable called "notes" is call the property Notes. Everything else is handled by the set method.