Re: [Vala] Creating bindings for Oracle OCI



Call it persistence or stuborness, but I found the answer! Woot!

My problem was the definition of buffer, which is what I thought. I got
close with:

string* buffer = "";

But the buffer was too small and I didn't know how to make it bigger.
The correct solution was:

char*  buffer = new char[512];

Low and behold, I have a working error message! I decided to start over
on this little project and stick as close as possible to the types that
oracle uses. I figured that was where my problem was, trying to use
string instead of char/uchar. Looking at the difference between the
generated c code for string and char, I'm not sure if string would work
or not. I'm guessing I could get it to work, but why, this works perfect
as far as I can tell.

Anyway.. thanks again for the help.. I can honestly say that I almost
fully understand the differences between: 

Value
*Value (and obviously **Value)
&Value

I'm sure there will be corner cases that will throw me, but at a high
level, I get it and I think that officially makes me dangerous now.. now
I just have to start moving towards the "good" side!

SMF

On Wed, 2009-06-17 at 18:31 +0200, Jiří Zárevúcky wrote:
Well, I don't know how the API you're binding works, but in Vala,
string is usually understood as an immutable nul-terminated UTF-8
encoded text. Maybe you're using something the wrong way?

I suppose it would be easier for you if you actually learned C better
first, then learned exactly how Vala translates to C.

Maybe you can attach your work so far along with a link to the C
documentation. That way someone could figure out what exactly is going
wrong. I suppose it could be me, but I'm not really that experienced
with Vala myself, yet.

2009/6/17 Shawn Ferris <shawn ferris gmail com>:
I'm sorry to keep pestering.. but if I omit the asterick, nothing
changes.. it still aborts.. What I did get to work, sorta, was to omit
the 'out'.. initially I got the error 'error: use of possibly unassigned
local variable `errbuf'' which I got around by declaring errbuf as
'string errbuf = ""'.. now, the buffer is filled, but with only 7
characters of the error:

ORA-121

which should be:

ORA-12154: TNS:could not resolve the connect identifier specified

Which I can get if I change the bufsiz arg from '(int)sizeof(string)' to
512.. but I then it's worse as I also get:

*** glibc detected *** ./x: free(): invalid next size (fast):
0x0000000000688510 ***

Which I presume is because I'm freeing more memory than the string
actually occupies? (I assume this is true, because if I change it to 16,
I get more of the message returned, without the error.. but I can't go
anywhere near the 66 chars needed.. not even 33)

The thing I don't understand is that the docs say if buffsiz isn't big
enough, OCIErrorGet will return null.. so, I'm lead to believe that
oracle is getting a big enough buffer, but somehow string is truncating
it? Should I not be using string?


On Wed, 2009-06-17 at 13:24 +0200, Jiří Zárevúcky wrote:
You have problem with pointers, again. ;) Once you add "out", it's not
a pointer anymore as far as Vala is concerned, so you have to omit the
asterisk. You are essentially replacing it.

2009/6/17 Shawn Ferris <shawn ferris gmail com>:
Ooops.. Resending, didn't realize this didn't go to the list.. my
apologies.

On Tue, 2009-06-16 at 21:44 -0600, Shawn Ferris wrote:
Man.. I'm so close I can smell it.. I actually have the bindings working
to the point were I am fetching a value from a table. Unfortunately, the
way it sits, I'm stuck with ints alone.. as soon as I try to return a
string, the code aborts.. there's actually two cases where the results
are the same and I'm assuming the fix for one will fix the other, so
I'll ask for help on the easier one. In this case, it's the ErrorGet
function defined as:

sword OCIErrorGet ( void      *hndlp,
                  ub4        recordno,
                  OraText       *sqlstate,
                  ub4        *errcodep,
                  OraText       *bufp,
                  ub4        bufsiz,
                  ub4        type );

My vapi definition:

  [CCode (cname = "OCIErrorGet")]
  public int ErrorGet (
    Error*       error,
    int          record,
    out string*  sqlstate,
    out int*     errcode,
    out string*  buffer,
    int          buffersz,
    HType        type
  );

And a C example:

  text errbuf[512];
  OCIErrorGet ((dvoid *) errhp, (ub4) 1, (text *) NULL, &errcode,
            errbuf, (ub4) sizeof(errbuf), (ub4) OCI_HTYPE_ERROR);

If I leave off errbuf (which should be the physical message string
assoctiate to errcode) everything works fine. EG:

    int*    errno;
    OCI.ErrorGet ( err, 1, null, out errno, null, 0, HType.ERROR);
    stdout.printf("Error - ORA-%5.5d (%s)\n", (int)errno, action);

I absolutely get the right error code (i can force which error I gen)
but as soon as I try to touch errbuf the program aborts.. I can not for
the life of me find the correct way to do this. Can someone point me in
the right direction? And then, I'll warn you that I'll have at least one
more email.. but more critique and style.. I'm assuming I haven't
followed the vala way, but I'm more interested in getting it to work and
addressing style later.

Thanks for the help!
SMF


_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list







[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]