DB-LIB question ( newbie question ) 
Author Message
 DB-LIB question ( newbie question )

Hi:

Could somebody tell  me what is wrong with the following code ?
When I run it, all I get is my prompt back. The table has the entry
'niranjan', 'T&F' in it.

I compile the program as
cc -I/sybase/include -L/sybase/lib example.c -lsybdb

The version is sybase 10.1

Also how does one get back a single row as a string. I need  to
delete trailing blanks from each field ? Any suggestion ?

i.e

while ( there are rows ) {
        fetch a row
        remove trailing blanks

Quote:
}

peace,

-- Niranjan

#include<sybfront.h>
#include<sybdb.h>
#include<syberror.h>
#include "sybdbex.h"

main()
{
        DBPROCESS *dbproc;
        LOGINREC *login;
        RETCODE return_code;

        login = dblogin();
        DBSETLUSER(login,USER);
        DBSETLPWD(login,PASSWORD);
        DBSETLAPP(login,"a.out");

        dbproc = dbopen(login, NULL );
        if(dbproc == NULL)
                exit(ERREXIT);  

        dbcmd(dbproc, "use tempdb");
        dbcmd(dbproc, "select * from emp");
        if(dbsqlexec(dbproc) == FAIL)
        {
                dbexit();
                exit(ERREXIT);
        }

        while(dbresults(dbproc) != NO_MORE_RESULTS)
                dbprrow(dbproc);

        dbexit();
        exit(STDEXIT);

Quote:
}



Sat, 01 Mar 1997 05:59:50 GMT
 DB-LIB question ( newbie question )

|> Could somebody tell  me what is wrong with the following code ?
|> When I run it, all I get is my prompt back. The table has the entry
|> 'niranjan', 'T&F' in it.
|>
|> I compile the program as
|> cc -I/sybase/include -L/sybase/lib example.c -lsybdb
|>
|> The version is sybase 10.1

Instead of doing

        dbcmd(dbproc, "use tempdb");

Try

        dbuse(dbproc, "tempdb");

Read up on "dbuse" in the Open Client manual.  Use that to establish the
database you want your application to use.

|> Also how does one get back a single row as a string. I need  to
|> delete trailing blanks from each field ? Any suggestion ?
|>
|> i.e
|>
|> while ( there are rows ) {
|>   fetch a row
|>   remove trailing blanks
|> }

You could do it in the SELECT statement you send to the server.  For
example,

        SELECT RTRIM(col1), RTRIM(col2) ...
        FROM tablename

Hope this helps.

                                Teresa Larson

+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
| Teresa A. Larson - Hughes STX Corporation                            |
| NASA/GSFC Code 933.0                        voice:  (301) 286-7867   |
| Greenbelt, Maryland  20771                  fax:    (301) 286-1777   |

+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
                        Standard disclaimer ...



Sat, 01 Mar 1997 21:41:48 GMT
 DB-LIB question ( newbie question )

Quote:
>        while(dbresults(dbproc) != NO_MORE_RESULTS)

        while( dbnextrow(dbproc) != NO_MORE_ROWS )

Quote:
>                dbprrow(dbproc);

I believe you need to add the call to dbnextrow as shown above.  

Jon



Sat, 01 Mar 1997 23:29:46 GMT
 DB-LIB question ( newbie question )

Quote:


>Subject: DB-LIB question ( newbie question )
>Date: 12 Sep 1994 21:59:50 GMT
>Hi:
>Could somebody tell  me what is wrong with the following code ?
>When I run it, all I get is my prompt back. The table has the entry
>'niranjan', 'T&F' in it.
>I compile the program as
>cc -I/sybase/include -L/sybase/lib example.c -lsybdb
>The version is sybase 10.1
>Also how does one get back a single row as a string. I need  to
>delete trailing blanks from each field ? Any suggestion ?
>i.e
>while ( there are rows ) {
>        fetch a row
>        remove trailing blanks
>}
>peace,
>-- Niranjan
>#include<sybfront.h>
>#include<sybdb.h>
>#include<syberror.h>
>#include "sybdbex.h"
>main()
>{
>        DBPROCESS *dbproc;
>        LOGINREC *login;
>        RETCODE return_code;
>        login = dblogin();
>        DBSETLUSER(login,USER);
>        DBSETLPWD(login,PASSWORD);
>        DBSETLAPP(login,"a.out");
>        dbproc = dbopen(login, NULL );
>        if(dbproc == NULL)
>                exit(ERREXIT);  
>        dbcmd(dbproc, "use tempdb");
>        dbcmd(dbproc, "select * from emp");
>        if(dbsqlexec(dbproc) == FAIL)
>        {
>                dbexit();
>                exit(ERREXIT);
>        }
>        while(dbresults(dbproc) != NO_MORE_RESULTS)
>                dbprrow(dbproc);
>        dbexit();
>        exit(STDEXIT);
>}

Your while loop is not checking for failure. dbprrow only works if the value
back from dbresults - SUCCEED. Also why are you "use" ing tempdb? Do you have
a reason for suspecting that tempdb will be holding your data at the time that
you query? Where is the static (production) database that will be filling
tempdb and how is that occurring?

Cliff High
Tenax SE



Sat, 01 Mar 1997 17:52:35 GMT
 
 [ 4 post ] 

 Relevant Pages 

1. DB-Lib versus OLE DB Performance Question

2. DB-Lib question/High speed access to SQL Server

3. Data Access Questions: VBSQL/DB-Lib --> ADO

4. Question - db-lib get list of servers

5. Question on the DB-Lib function dbnullbind

6. Data Access Questions: VBSQL/DB-Lib --> ADO

7. QUESTION: No-Wait DB-lib calls...

8. Question about DB-Lib..

9. QUESTION: Process termination on db-lib deadlock?

10. DB-LIB question

11. DB-Lib question: use of NULL indicator for Insert


 
Powered by phpBB® Forum Software