Introduction
It is a
useful tool
to minimize
your
database
related
code.
Just using
CDatabaseServer
by following
some steps,
you will
find it very
useful for
your
project.
Requirements
-
Your
database
retrieval
must
rely on
stored
procedures.
-
SQL
Server
must be
installed
on the
same
machine
where
this
code is
running.
Explanation
The reason
to write
this
article
is that our
database
applications
have somehow
redundant
code and may
cause
problems.
For example
ADO
library,
we use it
when we have
to make a
call to
database.
Usually its
our practice
that when we
need data
from
database,
we
open
connection
every time
and get data
in
RecordSet
object every
time...
I have tried
to implement
a class that
will fulfill
the request
of
database
calls
whether
incoming or
outgoing.
You guys
will really
enjoy when
you use it
in your C++
application.
I suggest
you to
follow these
steps:
-
For your
database
project,
add
provided
two
files
databaserver.h
and
databaserver.cpp.
-
Whenever
you need
data,
call
CDatabaseServer
's
methods
getExecStoredProcedure
by
putting
arguments
correctly.
That
method
will
return
VARIANT
array
using
GetRows
method
of
ADO
Recordset
so that
data can
be
marshaled
properly.
-
Whenever
you need
to
insert/update
data,
then
call
CDatabaseServer
's
method
setExecStoredProcedure
.
That
method
will
return
long
value
which
could be
ID
entity
to which
operation
was
performed.
-
Now it's
your
responsibility
to
manually
update
your
connection
information
in the
method
SetConnectionsting
.
-
Create
database
in
SQL
Server,
modify
local
variable
szDatabase
with
newly
created
database
name in
the
setConnectionsting
method.
-
When
calling
getExecStoredProcedure
/setExecStoredProcedure
,
be
careful
to send
proper
stored
procedure
name and
and its
parameter
in
SAFEARRAY
pointer.
-
Parameter
must be
in the
same
sequence
as in
stored
procedure.
Please don’t
hesitate to
ucancode.net about
any kind of
problems and
also if you
guys have
some better
suggestions,
then keep me
informed.