Posts Tagged ‘Code’

Refactoring DBObject

DBObject has come a long way recently and there is a lot of duplicated code. So I think now is a good time to refactor. Let’s start with the most obvious items. There are only 11 methods in the DBObject, 7 of them take string connection, 4 take string index_column, and another 4 take string [...]

  • Share/Bookmark
Read the rest of this entry »

Checking if record/object already exists.

Last time I said it would be nice to know if the record already exists in the database. When you want a one-to-many relationship, you don’t want to accidentally add the same record more than once. If an object is made that has the exact same values as another record, we shouldn’t add it, but [...]

  • Share/Bookmark
Read the rest of this entry »

DBObject with Self Updating.

I’ve added self updating and Insert to the DBObject. I’ve also changed the naming of the columns it pulls from the database. Each column property now starts with “column_”.

  • Share/Bookmark
Read the rest of this entry »

Get Column name from MySqlDataReader

Recently someone found my blog by searching google asking how to get the column name from a MySqlDataReader. I doubt they found the answer on my blog, so I figured I’d write about, just in case anyone else needs to know.

  • Share/Bookmark
Read the rest of this entry »

SubSonic and ORM

Looking into other ORMs and Linq I came across subsonic. I watched the video and build a quick little sample application with it. I had a slight problem at first because it kept giving me an error with my MySql.Data reference. I upgraded my DLL and played around with it some more, still no luck. [...]

  • Share/Bookmark
Read the rest of this entry »

GetProperty() SetProperty()

I created the GetProperty() and SetProperty() methods to allow the base object to manage holding the variables needed for the object. I’ve implemented these methods on my old object classes just to test them out in some real world examples. I’ve found two problems, the first is that sometimes I only want to set a [...]

  • Share/Bookmark
Read the rest of this entry »

Join is working

I have the join working but it’s not pretty. _tags = DBObject.WhereJoin(“user_id”, “=”, this.ID, typeof(DBTag), “tag_user”, “tag_id”, “id”, DBUser._conn); Right now, in the Where you have to specify all the information about the Join, the table, the columns, etc. and it doesn’t use a property but the column name (because there is no object for [...]

  • Share/Bookmark
Read the rest of this entry »

helpers

I which I could put this in the base class somehow, but we can simplify the code if the inherited class override the By and Where methods like so /// /// Get a single User By the property and value specified /// /// /// /// static public DBUser By(string property, object value) { return (DBUser)DBObject.By(property, [...]

  • Share/Bookmark
Read the rest of this entry »

DBObject.Where

Ok it works. I also created a checker for the opertators so we don’t get invalid/malicious code. /// /// Returns a DBList of objects that match the Where /// /// Property to Match /// “=”, “<”, “>”, “LIKE” /// Value to Match /// Type of the object to get (Must inherent from DBOBject) /// Connection [...]

  • Share/Bookmark
Read the rest of this entry »

DBObject rev .03

Alright, now I have a working .By It actually simplifies things a lot, to the point I’m starting to double think making everything static. As you can see, you can simply call something like: DBUser chris = (DBUser)DBObject.By(“firstname”, “chris”, typeof(DBUser), Utility.connMy); DBUser bob = (DBUser)DBObject.By(“id”, “1327″, typeof(DBUser), Utility.connMy); And get back a valid user. This [...]

  • Share/Bookmark
Read the rest of this entry »