Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

dbdata float problem

Posted on 2004-10-10
11
Medium Priority
?
291 Views
Last Modified: 2008-03-04
I'm attempting to assign a column to the FloatVar below via dbdata, but I keep getting an unspecified run-time error.  The dbdata assignment to CharVar works fine.  What could be causing this?

#define DBNTWIN32
#include "windows.h"
#include <sqlfront.h>
#include <sqldb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>

PDBPROCESS dbproc;
PLOGINREC login;
RETCODE result_code;
DBFLT8 FloatVar;

char sql_stmt[256];
char CharVar[51];

void main() {
  void sqlconn();

  sqlconn();

  sprintf(sql_stmt,"SELECT FloatVar,CharVar FROM TestTable");
  dbcmd(dbproc,sql_stmt);
  dbsqlexec(dbproc);
  dbresults(dbproc);

  while (dbnextrow(dbproc) != NO_MORE_ROWS) {
    FloatVar = *((DBFLT8 *)dbdata(dbproc,1));
    strncpy(CharVar,(char *)dbdata(dbproc,2),(int)dbdatlen(dbproc,2));

    fprintf(stdout,"FloatVar: %s\tCharVar: %s\n",FloatVar,CharVar);
  }
}
0
Comment
Question by:arichexe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 17

Expert Comment

by:rstaveley
ID: 12272375
Would you expect DBFLT8 to be printable with format specifier %s ??
0
 

Author Comment

by:arichexe
ID: 12272527
I still get the run-time crash.
0
 

Author Comment

by:arichexe
ID: 12279591
I think the problem has to do with nulls, because when I change my select to isnull FloatVar to 0, it works.  How would I change dbdata to accommodate nulls in FloatVar?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:rstaveley
ID: 12279903
0
 

Author Comment

by:arichexe
ID: 12279933
I can't get dbbind to work, because of a linkage problem.
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 12280023
It is a C library I gather (must confess I've not used it). Is it possible that you are calling it from a C++ module and the header hasn't done extern "C"... and thus it has expected a C++ name-manged function...? Just a guess. Can you show me the linker error?
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 12280180
VC7 and 7.1 doesn't have support for DB-Library (probably because they are tying to get you to use ADO, OLE DB, or ODBC to access SQL Server nowadays), but I notice that the headers in VC 6 do...

#ifdef __cplusplus
      extern "C" {
#endif

If you are using VC6 my guess isn't going to be right... but do let me know what the linker error is.
0
 

Author Comment

by:arichexe
ID: 12290389
I'm using VC6.  Here's the link error on dbbind:

Performing Custom Build Step on .\test.sc
ESQL test.sc:
Compiling...
test.cpp
c:\test\test.cpp(25) : error C2664: 'dbbind' : cannot convert parameter 5 from 'char *' to 'unsigned char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 12290431
That's a compiler error not a link error. Do the reinterpret_cast<unsigned char*> and you'll be in business.
0
 

Author Comment

by:arichexe
ID: 12291285
How would I code the "reinterpret_cast<unsigned char*>" in the below module?

PDBPROCESS dbproc;
PLOGINREC login;
RETCODE result_code;

char sql_stmt[256];
char testvar[51];

void main() {
  void sqlconn();

  sqlconn();

  sprintf(sql_stmt,"SELECT testvar FROM testtable");
  dbcmd(dbproc,sql_stmt);
  dbsqlexec(dbproc);

  while ((result_code = dbresults(dbproc)) != NO_MORE_RESULTS) {
    if (result_code == SUCCEED) {
       dbbind (dbproc,1,NTBSTRINGBIND,(DBINT) 0,(char *) testvar);

       while (dbnextrow(dbproc) != NO_MORE_ROWS) {
         fprintf(stdout,"testvar: %s\n",testvar);
       }
     }
  }
}
0
 
LVL 17

Accepted Solution

by:
rstaveley earned 500 total points
ID: 12291369
Here's the C-cast way to do it:

  dbbind (dbproc,1,NTBSTRINGBIND,(DBINT) 0,(unsigned char *) testvar);

But it's more in the spirit of C++ to write

  dbbind (dbproc,1,NTBSTRINGBIND,(DBINT) 0,reinterpret_cast<unsigned char*>(testvar));

Either will work, but C-casting is less specific than C++'s casting.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question