Page 7 of 9

Posted: Wed May 21, 2008 11:33 am
by Fangbeast
No idea Paul, sorry:):)

Posted: Wed May 21, 2008 2:05 pm
by Fangbeast
Kiffi wrote:
Fangbeast wrote:I'm using an older include
this one: http://www.purebasic.fr/english/viewtop ... 667#194667?

Testing this include with your snippet and PB 4.1 also
works fine and no error occurred ;-)

Greetings ... Kiffi
I tried with that include, no joy. The "SQliteGetTable" method works, the "SQLitePrepare" doesn't.

Just thinking about what Paul Dwyer said about database conversion and types etc and that error message ""ERROR, specified address is null"

When I first created my database a year ago, I was using pb4.x and the latest sqlite dll at that time and getting those errors all the time until someone pointed out that I should be doing this:

PeekS(MyData, #PB_Any, #PB_Ascii)

I wasn't using Unicode in either the compiler or the database at the time and doing that to PEEKS cured it, no more address is null errors.

Does this give you any ideas? Because I have no clue (lol) !

Posted: Wed May 21, 2008 2:54 pm
by Kiffi
@Fangbeast:

first of all: check out if this code works for you:

http://test.tuebben.de/protozoa.zip

(this zip includes the pb-source and a sample-database)

If the code works without any problems, you have to check
if your database is broken.

Greetings ... Kiffi

Posted: Wed May 21, 2008 2:59 pm
by Fangbeast
Kiffi wrote:@Fangbeast:

http://test.tuebben.de/protozoa.zip

Greetings ... Kiffi
protozoa??? ROFLMAO!! You made my day:):)

You are not going to believe this

Posted: Wed May 21, 2008 3:21 pm
by Fangbeast
I pass this path to the sqlite include to OpenLibrary and it's always worked for me in the past. It works when using GetTable but not for prepare

"\Development\Resources\Libraries\sqlite3upx.dll"

As soon as I put the drive letter in, it works for Prepare as well??

"C:\Development\Resources\Libraries\sqlite3upx.dll"

Why in hell does a drive letter make a difference to using the lib in the "prepare.

=================================================

Works fine with your database but not with mine. No matter what I do, only the GetTable method works.

Thanks for trying Kiffi, at least my old sqlite code works still and so does the GetTable method with Thomas's and your include, so I know my database isn't broken.

I think I'd better give up before my hair turns white!

Posted: Tue Jun 10, 2008 11:06 am
by Fangbeast
Using the 4.2 specific includes with new code and encountered an error when an empty string is sent to the query. Error is "Specified Address is Null"

Should I bulletproof my routine to NOT send an empty string to the query or should this routine be bulletproofed?

Code: Select all

Procedure.s SQLiteColumnText(lStatement.l, lColumn.l)
  CompilerIf #PB_Compiler_Unicode
  ProcedureReturn PeekS(sqlite3_column_text16(lStatement, lColumn))
  CompilerElse
  ProcedureReturn PeekS(sqlite3_column_text(lStatement, lColumn));<< this one throws up that error.
  CompilerEndIf
EndProcedure

Posted: Tue Jun 10, 2008 1:31 pm
by ts-soft
Only the special tablefunctions have a test on it, the other routines only
wrappers, but i will add a nullpointercheck for functions with Stringresult.

greetings
Thomas

// edit:
done
http://www.purebasic.fr/english/viewtop ... 853#240853

Posted: Tue Jun 10, 2008 1:45 pm
by Fangbeast
ts-soft wrote:Only the special tablefunctions have a test on it, the other routines only
wrappers, but i will add a nullpointercheck for functions with Stringresult.

greetings
Thomas

// edit:
done
http://www.purebasic.fr/english/viewtop ... 853#240853
Hi Thomas, I wasn't sure if I was right or wrong so did some more testing. It seems I can crash it by just sending a single space character. Is that equivalent to a null somehow?

Posted: Tue Jun 10, 2008 2:13 pm
by ts-soft
I can't add a check is query okay, sry

Posted: Tue Jun 10, 2008 3:15 pm
by Fangbeast
ts-soft wrote:I can't add a check is query okay, sry
No problems, thanks Thomas. I added checks in my code.

Posted: Fri Aug 01, 2008 4:34 am
by Fangbeast
I created an extra column in my database with a professional tool and when this code gets to it, it crashes. It must have created the column with null values by default but there is no way for me to examine the column contents that I know of.

How can I bulletproof this procedure so that it doesn't crash with "Specified address is null" as it must be hitting a null in that column?

Code: Select all

Procedure.s SQLiteColumnText(lStatement.l, lColumn.l)
  CompilerIf #PB_Compiler_Unicode
    If SQ3\column_text16
      ProcedureReturn PeekS(SQ3\column_text16(lStatement, lColumn))
    EndIf
  CompilerElse
    If SQ3\column_text
      ProcedureReturn PeekS(SQ3\column_text(lStatement, lColumn))
    EndIf
  CompilerEndIf
  ProcedureReturn ""
EndProcedure

Posted: Fri Aug 01, 2008 10:13 am
by srod
What about sticking in a If SQ3\column_text(lStatement, lColumn) before the PeekS() etc. or have I misunderstood?

Code: Select all

Procedure.s SQLiteColumnText(lStatement.l, lColumn.l) 
  CompilerIf #PB_Compiler_Unicode 
    If SQ3\column_text16 And SQ3\column_text16(lStatement, lColumn)
      ProcedureReturn PeekS(SQ3\column_text16(lStatement, lColumn)) 
    EndIf 
  CompilerElse 
    If SQ3\column_text And SQ3\column_text(lStatement, lColumn)
      ProcedureReturn PeekS(SQ3\column_text(lStatement, lColumn)) 
    EndIf 
  CompilerEndIf 
  ProcedureReturn "" 
EndProcedure

Posted: Fri Aug 01, 2008 1:07 pm
by Fangbeast
You understood perfectly and I was speaking Fanglish at the time. Didn't know you spoke my dialect??? It worked, thank you. I don't know why it works, but it does :):):)

Posted: Fri Aug 01, 2008 1:19 pm
by srod
Well PeekS() will crash if you supply it with a null address and your SQLite wrapper there returns a null pointer in the cases where there is no text in the field etc. Put the two together and, without the checks introduced above, you end up using PeekS() on a null address ... crash!!!

:)

[SOLVED]

Posted: Mon Aug 11, 2008 9:11 am
by Fangbeast
How do I modify the below code so that it returns all my text? If I save a block of text with invisible CR/LF pairs, I can check that the data is in fact in the database (with a professional SQL tool) but when I retrieve the text, it is truncated at the first CR/LF encountered as if it were a null char?

Code: Select all

Procedure.s SQLiteColumnText(lStatement.l, lColumn.l)
  CompilerIf #PB_Compiler_Unicode
    If SQ3\column_text16
      ProcedureReturn PeekS(SQ3\column_text16(lStatement, lColumn))
    EndIf
  CompilerElse
    If SQ3\column_text
      ProcedureReturn PeekS(SQ3\column_text(lStatement, lColumn))
    EndIf
  CompilerEndIf
  ProcedureReturn ""
EndProcedure
*EDIT* It wasn't the routine at all. it was the fact that there were CR/LF pairs (0D0A) in one field, and I was sending the returned data to a ListIconGadget which uses 0A (CHR(10)) to separate the columns and thus truncating the data and messing up the display.

ARRGHGHGHGH!!!