Adding to database?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding to database?

Craig H. Anderson
How can one add rows to an empty
database with the database package?

Thanks


Reply | Threaded
Open this post in threaded view
|

Re: Adding to database?

Bill Schwab-2
Craig,

> How can one add rows to an empty
> database with the database package?

Execute a SQL statement - the one you want is described at:

  http://msdn.microsoft.com/library/psdk/dasdk/lr309sj0.htm

My suspicion is that preparing the statement (see the DatbaseConnection
docs) will make things a little easier.  Without preparing statements,
you'll find that a little experimentation will usually do the trick since
the delimiters are generally limited to single quotes.  Without preparing,
you'll probably find that $| in a string will cause problems, and you'll
have to put time stamps in some kind of crazy format like {ts YYYY-DD-MM
HH:MM:SS} (that's not it, but, you get the idea.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Adding to database? An example

Craig H. Anderson
In reply to this post by Craig H. Anderson
I'm having trouble replying in outlook. Sorry if multiple posts
or emails show up.
Here is an example I came up with:

1) Connect to database and get table description
dbc := (DBConnection new) dsn: 'ConstraintsDB'; connect.
xx := dbc tables.
xx := dbc columns: 'tblLetterType'.
" a DBColAttr(1, LetterTypeId, SQLInteger, 4) "
" a DBColAttr(2, LetterType, SQLVarChar, 100) "
" a DBColAttr(3, Description, SQLVarChar, 100) "

2) Prepare an insert statement.
insertStatement := dbc prepare: 'insert into tblLetterType (LetterTypeId,
LetterType, Description) values (?, ?, ?)'.
insertStatement paramCols: ((dbc columns: 'tblLetterType') asArray).

3) Insert rows with the statement.
insertStatement values: #( 99 'aaa' 'bbb').
insertStatement exec.
insertStatement values: #( 100 'ccc' 'ddd').
insertStatement exec.

4) Check that the new rows are there.
rs := dbc query: 'select * from tblLetterType where LetterTypeId >= 99'.

5) Marvel at how much easier this was than using VisualC++. (I use Visual
Studio at work)

"Craig H. Anderson" <[hidden email]> wrote in message
news:1imR5.207761$[hidden email]...
> How can one add rows to an empty
> database with the database package?
>
> Thanks
>
>
>