473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Abstracting SQL Statements In An Object


I am looking for comments on something that lets me abstract database
updates in an object.

Lemme explain what I am thinking:

Lets say I have an object Person with...

SetFirstName()
SetLastName()

etc.

(Basically the goal is for the development team to use the objects and
not try to write to the database themselves.)

Well, what I am trying to avoid is when I call SetFirstName() and then
call SetLastName() the execution of two UPDATE statements. I would like
to combine it all into one single UPDATE or INSERT so I am not beating
up on the database.

I am thinking I would need to store the changes into variables local to
the class and then maybe calling a SendSQL() function or something like
that to generated SQL changes of the data to the database.

Something like:

$DB->query("BEGIN TRANSACTION");

// Person fools around with $DB
$Person->SetFirstName("Something");
$Person->SetLastName ("Something");
$Person->SendSQL();

// Another object fooling around with $DB
$AnotherOBj->SomeMethod ("Foo");
$AnotherOBj->SendSQL();

$DB->query ("COMMIT TRANSACTION");

Anyhow - opinions and experiences are welcome!
Jul 19 '05 #1
1 1543
Scott Auge wrote:
I am looking for comments on something that lets me abstract database
updates in an object.

Lemme explain what I am thinking:

Lets say I have an object Person with...

SetFirstName()
SetLastName()

etc.

(Basically the goal is for the development team to use the objects and
not try to write to the database themselves.)

Well, what I am trying to avoid is when I call SetFirstName() and then
call SetLastName() the execution of two UPDATE statements. I would like
to combine it all into one single UPDATE or INSERT so I am not beating
up on the database.

I am thinking I would need to store the changes into variables local to
the class and then maybe calling a SendSQL() function or something like
that to generated SQL changes of the data to the database.

Something like:

$DB->query("BEGIN TRANSACTION");

// Person fools around with $DB
$Person->SetFirstName("Something");
$Person->SetLastName ("Something");
$Person->SendSQL();

// Another object fooling around with $DB
$AnotherOBj->SomeMethod ("Foo");
$AnotherOBj->SendSQL();

$DB->query ("COMMIT TRANSACTION");

Anyhow - opinions and experiences are welcome!


Scott,

Generally, classes do not access the database unless specifically requested.
You might have four class members, for instance - fetch(), update(), insert()
and delete(). Each does its respective operations based on the data in the
current object (fetch() usually requires a key).

Another common class is the list class, which fetches an array of objects based
on select criteria.

But no, you do NOT want to update the database every time you issue a
GetFirstName() or SetFirstName(). The former needlessly requires access to the
database, and the latter may update the database when you don't want it updated
(i.e. change the name - but verify the change with the user before actually
updating the database).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Scott Auge | last post by:
I am looking for comments on something that lets me abstract database updates in an object. Lemme explain what I am thinking: Lets say I have an object Person with... SetFirstName()...
7
by: John Thorner | last post by:
Hi, I am creating a new thread for each of the connections to the server: public class Node_C { .... while (listening) { Socket client_socket = server_socket.accept(); Node_CThread node ...
11
by: dmbkiwi | last post by:
I am new to this group, and relatively new to python programming, however, have encountered a problem I just cannot solve through reading the documentation, and searching this group on google. I...
1
by: Tom D | last post by:
I'm rewriting a database interface that our company currently has. Currently it's using the Pear::DB interface, but we found that that was introducing a bit too much overhead. I'm rewriting the...
1
by: Frank Rizzo | last post by:
I have an app that has to connect to various data sources (ms sql server, sybase, etc...). For this reason I have OdbcConnection, OleDb Connection and SqlClient objects. When an error happens, I...
2
by: nevin | last post by:
Hi all, I'm looking at the Amazon web services and get them to work fine. But on any given call I want to be able to use either the US or the EU schemas which are in the project as two different...
0
by: Tim Barnes | last post by:
I am going through a revision of my product where I am trying to abstract out the data access layer, where I have traditionally just dragged/dropped data adapters and generated datasets using...
11
by: Full Decent | last post by:
Hey all! I've been using PHP for a while and I'm hearing that I should look into using it OO. I'm looking into making changes to the program Camera Life (http://fdcl.sf.net). I want to abstract...
1
by: | last post by:
Hi. This is a a semi-newbie question about how to store arbitrary information about my apps such that I can code quickly, mimizing complexity and the number of things I have to hold in my brain. I...
7
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Run multiple SQL statements from ASP/ADO to an Oracle 10g. Please help, I'm trying to write an ASP page to use ADO to run a long query against an Oracle 10g database, to create tables,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.