Re: [sqlite] sqlite3_column_text() returning partial results

2011-12-21 Thread Jacob A. Camp
There it is, when I printed this value out to a txt file everything was there. 

Apparently there is some sort of character limit when displaying strings in 
debug mode in Visual Studio 2010, news to me...

Thanks everyone!

-Original Message-
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] 
On Behalf Of Pavel Ivanov
Sent: Wednesday, December 21, 2011 2:33 PM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] sqlite3_column_text() returning partial results

Now, this is a very good test case and explanation what happens, except...

How did you check value of CString testing after iterating though the entire 
char array? Did you look at it in your debugger? Maybe your debugger is not 
capable of showing CString contents longer than 2048 symbols? The value of 
string testing you gave with Windows-style line ends gives me 2040 bytes, 
indentation of the next line is 8 bytes, so if total limit is 2048 bytes then 
you won't see any contents of the next line...

Can you output contents of CString testing using printf() and see if it shows 
the same 2040 bytes?


Pavel


On Wed, Dec 21, 2011 at 1:34 PM, Jacob A. Camp  wrote:
> So delving further into this has gotten me nothing else; this is the best I 
> could do to simplify this to understandable steps.
>
> (I'm new to this service so no idea if attachments are allows so sorry 
> about the length in advance)
>
> I have this code:
>
>                sqlite3_stmt* state = NULL;
>                CString sql = _T("SELECT RelationshipHierarchyXML FROM 
> TlAssembly WHERE id=?");
>                //Query the database
>                RawSQLTlID (sql, id, &state);
>                bytes = sqlite3_column_bytes(state, 0); //This line 
> returns 8955
>                //Try getting data as blob
>                const void * temp = sqlite3_column_blob(state, 0);
>                //Set the size for simplification
>                char chararray[9000];
>                //Copy value into the char array
>                memcpy( chararray , temp , bytes);
>                CString testing;
>                //Iterate through all elements
>                for (int x = 0; x < 8999; x++)
>                {
>                int temp = chararray[x];
>                char temp2 = chararray[x];
>
>                //if the char is null or not supportted don't append it 
> to CString
>                if (temp < 1 || temp > 255)
>                {
>                //This gets hit a few times with negative int values
>                temp = temp;
>                }
>                else
>                {
>                //Append the char to the XML string
>                testing.AppendChar(temp2);
>                }
>                }
>
>                return success;
>
> At this point the CString testing contains on a portion of the characters of 
> the XML field which makes it unusable.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

**
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mastercam.com
**
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] sqlite3_column_text() returning partial results

2011-12-21 Thread Jacob A. Camp
4 FLAT ENDMILL
  
  
I
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
  
  

  true
  
I
1
0
0
0
0
1
0
0
0
0
1
0
0
2.5
0
1
  
  Target
  DefaultTarget
  
I
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
  
  


  true
  
I
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
  
  LinearAxis
  
  
I
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
  
  

  true
  
I
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
  
  Real Holder
  
  
I
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
  
  

  true
  
I
1
0
0
0
0
1
0
0
0
0
1
0
0
6.12099987
0
1
  
  Target
  DefaultTarget
  
I
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
  
  

  
  #6699cc
  1
  Holder
  0
  d22d6e4c-be03-471e-bcac-0e5d12852fb2

  
  0
  1
  0
  0
  2.5
  


  
  0.75
  1.3118700546473194
  Y

  
  #6699cc
  1
  Tool
  1.3118700546473194
  ----

  
  
  
  false
  VerticalLathe
  
  
  
  
",

-Original Message-
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] 
On Behalf Of Pavel Ivanov
Sent: Wednesday, December 21, 2011 11:20 AM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] sqlite3_column_text() returning partial results

On Wed, Dec 21, 2011 at 10:41 AM, Jacob A. Camp  
wrote:
> I have a line of code that executes that line:
>
> const unsigned char * temp2 = sqlite3_column_text(state, 0);
>
> This queries the database and after the call is complete I pass this value to 
> another function. This function then fails because temp2 points to a location 
> that contains the incomplete text. I then can view this text using my 
> debugger and I can see that the value has been clipped and the XML is invalid.

Let me ask Igor's questions once again. How does your function understand that 
text is incomplete? Your debugger can show you incomplete string because temp2 
is not a zero-terminated string, it can contain zeros in the middle.

> Trying to access memory locations outside whatever is allocated by the return 
> of sqlite3_column_text sounds like it would result in undefined behavior?

How do you know how much memory sqlite3_column_text allocated for the return?

> sqlite3_column_bytes returns 8960 if that's helpful.

Hint: the abov

Re: [sqlite] sqlite3_column_text() returning partial results

2011-12-21 Thread Jacob A. Camp
I have a line of code that executes that line:

const unsigned char * temp2 = sqlite3_column_text(state, 0);

This queries the database and after the call is complete I pass this value to 
another function. This function then fails because temp2 points to a location 
that contains the incomplete text. I then can view this text using my debugger 
and I can see that the value has been clipped and the XML is invalid. 

Trying to access memory locations outside whatever is allocated by the return 
of sqlite3_column_text sounds like it would result in undefined behavior?

sqlite3_column_bytes returns 8960 if that's helpful.

-Original Message-
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] 
On Behalf Of Igor Tandetnik
Sent: Wednesday, December 21, 2011 10:29 AM
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] sqlite3_column_text() returning partial results

Jake  wrote:
> For the previous post asking what occurs after 2030, there's nothing

What do you mean, nothing? What exactly happens when you try to access p[2030]?

> because the
> returned value is only allocated for those characters.

What makes you believe this?
-- 
Igor Tandetnik

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

**
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mastercam.com
**
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] sqlite3_column_text() returning partial results

2011-12-21 Thread Jacob A. Camp
Hello,

I've been looking into an issue that a few of our programmers have looked at as 
well and it left us all wondering. Basically, our database has a VARCHAR column 
that has an XML file written to it when the object is manipulated. I can use a 
tool to view the database file and I can ensure that the entire field is filled 
out correctly and the XML is correctly formed.

The field in the database contains 8955 characters and when I execute the 
sqlite3_column_text() on that specific column to access the data, the const 
unsigned char* that's returned only contains 2030 characters and the XML file 
that I'm trying to reconstruct from it then becomes unusable. I even attempted 
digging into the SQLite class and it seems that this value is obtained from the 
official function calls.

In sqlite3.c:

static Mem *columnMem(sqlite3_stmt *pStmt, int i){
  Vdbe *pVm;
  int vals;
  Mem *pOut;

  pVm = (Vdbe *)pStmt;
  if( pVm && pVm->pResultSet!=0 && inResColumn && i>=0 ){
sqlite3_mutex_enter(pVm->db->mutex);
vals = sqlite3_data_count(pStmt);
pOut = &pVm->pResultSet[i];

After the last line has been executed pOut contains members z and zMalloc which 
both contain the same memory location that points to the char* that contains 
the first 2030 characters and none of the rest that are stored in the VARCHAR 
field.

Is there some limit to the amount of data that can be returned by this 
function? I read over most of the documentation and didn't see it mentioning 
any sort of restriction.

Thanks in advance,
--Jake

**
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mastercam.com
**
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users