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.
Supporting Code:
bool TlToolLibrarySQL::RawSQLTlID (const CString& sql, const
TlID& id, sqlite3_stmt** statement, UINT expectedResult)
{
bool found = false;
// Pointer to the uncompiled portion of the SQL query
const char* unused = NULL;
// Prepare the SQL statement
int result = sqlite3_prepare_v2 (m_db, sql, -1, statement,
&unused);
// Bind the GUID ID to the statement
GUID tlid = id;
int result1 = sqlite3_bind_blob (*statement, 1, &tlid,
sizeof(tlid), SQLITE_TRANSIENT);
// If we prepared and got a row back, we are successful!
if (SQLITE_OK == result && SQLITE_OK == result1)
{
if (expectedResult == sqlite3_step (*statement))
{
found = true;
}
else
{
//Try again with a String GUID instead
sqlite3_reset (*statement);
sqlite3_clear_bindings (*statement);
result1 = sqlite3_bind_text (*statement, 1,
id.ToString(), -1, SQLITE_TRANSIENT);
if (SQLITE_OK == result1 && expectedResult ==
sqlite3_step (*statement))
{
found = true;
}
}
}
return found;
}
Value of CString testing after iterating though the entire char array:
"<?xml version="1.0" encoding="utf-8"?>
<Machine xmlns:i="http://www.w3.org/2001/XMLSchema-instance" z:Id="i1"
xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/"
xmlns="http://schemas.datacontract.org/2004/07/MDM.MachineDefinition.Models">
<IsVisible>true</IsVisible>
<ModelingTransformation z:Id="i2">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</ModelingTransformation>
<Name>Machine</Name>
<Tag i:nil="true" />
<Transformation z:Id="i3">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</Transformation>
<Components>
<Component z:Id="i4" i:type="ToolProfile">
<IsVisible>true</IsVisible>
<ModelingTransformation z:Id="i5">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</ModelingTransformation>
<Name> 3/8 DRILL</Name>
<Tag i:nil="true" />
<Transformation z:Id="i6">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
CSV Dump of the TlAssembly Table:
ID,Name,Description,MainHolder,MainTool,ToolNumber,MachineGroup,RelationshipHierarchyXML,Stickout
{9B6CB288-E5E0-4A8A-88C8-20E3A09A7429}, 3/8 DRILL
Assembly,"",{351FDBA2-B09F-4264-8227-8FE41C26865C},{02BBEE7C-7856-4E3C-9FDB-FFFB17050197},128,0,"?<?xml
version=""1.0"" encoding=""utf-8""?>
<Machine xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" z:Id=""i1""
xmlns:z=""http://schemas.microsoft.com/2003/10/Serialization/""
xmlns=""http://schemas.datacontract.org/2004/07/MDM.MachineDefinition.Models"">
<IsVisible>true</IsVisible>
<ModelingTransformation z:Id=""i2"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</ModelingTransformation>
<Name>Machine</Name>
<Tag i:nil=""true"" />
<Transformation z:Id=""i3"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</Transformation>
<Components>
<Component z:Id=""i4"" i:type=""ToolProfile"">
<IsVisible>true</IsVisible>
<ModelingTransformation z:Id=""i5"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</ModelingTransformation>
<Name> 3/8 DRILL</Name>
<Tag i:nil=""true"" />
<Transformation z:Id=""i6"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</Transformation>
<Components>
<Component z:Id=""i7"" i:type=""Group"">
<IsVisible>true</IsVisible>
<ModelingTransformation z:Id=""i8"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>3</M42>
<M43>0</M43>
<M44>1</M44>
</ModelingTransformation>
<Name>Target</Name>
<Tag>DefaultTarget</Tag>
<Transformation z:Id=""i9"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</Transformation>
<Components />
</Component>
<Component z:Id=""i10"" i:type=""LinearAxis"">
<IsVisible>true</IsVisible>
<ModelingTransformation z:Id=""i11"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</ModelingTransformation>
<Name>LinearAxis</Name>
<Tag i:nil=""true"" />
<Transformation z:Id=""i12"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</Transformation>
<Components>
<Component z:Id=""i13"" i:type=""ToolProfile"">
<IsVisible>true</IsVisible>
<ModelingTransformation z:Id=""i14"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</ModelingTransformation>
<Name>-- tp_tool Default Holder --</Name>
<Tag i:nil=""true"" />
<Transformation z:Id=""i15"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</Transformation>
<Components>
<Component z:Id=""i16"" i:type=""Group"">
<IsVisible>true</IsVisible>
<ModelingTransformation z:Id=""i17"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>1</M42>
<M43>0</M43>
<M44>1</M44>
</ModelingTransformation>
<Name>Target</Name>
<Tag>DefaultTarget</Tag>
<Transformation z:Id=""i18"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</Transformation>
<Components />
</Component>
</Components>
<HexColor>#6699cc</HexColor>
<Opacity>1</Opacity>
<ProfileType>Holder</ProfileType>
<StickOut>0</StickOut>
<ToolID>351fdba2-b09f-4264-8227-8fe41c26865c</ToolID>
</Component>
</Components>
<DirectionX>0</DirectionX>
<DirectionY>1</DirectionY>
<DirectionZ>0</DirectionZ>
<InitialPosition>0</InitialPosition>
<Max>3</Max>
<MaxFeedrate z:Id=""i19"">
<Inch i:nil=""true"" />
<Metric i:nil=""true"" />
</MaxFeedrate>
<Min>2.5</Min>
<Position>3</Position>
<AxisType>Y</AxisType>
</Component>
</Components>
<HexColor>#6699cc</HexColor>
<Opacity>1</Opacity>
<ProfileType>Tool</ProfileType>
<StickOut>3</StickOut>
<ToolID>00000000-0000-0000-0000-000000000000</ToolID>
</Component>
</Components>
<Control></Control>
<Family></Family>
<IsMetric>false</IsMetric>
<MachineToolType>VerticalLathe</MachineToolType>
<Manufacturer></Manufacturer>
<Model></Model>
<Series></Series>
<SubModel></SubModel>
</Machine>",
{792708B6-2352-4B1D-89C4-FAA65E4EA3F1},EPIC 1/4 FLAT ENDMILL
Assembly,"",{D22D6E4C-BE03-471E-BCAC-0E5D12852FB2},{76188D13-D397-4F06-8354-5019A8DD1D05},235,0,"?<?xml
version=""1.0"" encoding=""utf-8""?>
<Machine xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" z:Id=""i1""
xmlns:z=""http://schemas.microsoft.com/2003/10/Serialization/""
xmlns=""http://schemas.datacontract.org/2004/07/MDM.MachineDefinition.Models"">
<IsVisible>true</IsVisible>
<ModelingTransformation z:Id=""i2"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</ModelingTransformation>
<Name>Machine</Name>
<Tag i:nil=""true"" />
<Transformation z:Id=""i3"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</Transformation>
<Components>
<Component z:Id=""i4"" i:type=""ToolProfile"">
<IsVisible>true</IsVisible>
<ModelingTransformation z:Id=""i5"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</ModelingTransformation>
<Name>MAGIC 1/4 FLAT ENDMILL</Name>
<Tag i:nil=""true"" />
<Transformation z:Id=""i6"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</Transformation>
<Components>
<Component z:Id=""i7"" i:type=""Group"">
<IsVisible>true</IsVisible>
<ModelingTransformation z:Id=""i8"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>2.5</M42>
<M43>0</M43>
<M44>1</M44>
</ModelingTransformation>
<Name>Target</Name>
<Tag>DefaultTarget</Tag>
<Transformation z:Id=""i9"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</Transformation>
<Components />
</Component>
<Component z:Id=""i10"" i:type=""LinearAxis"">
<IsVisible>true</IsVisible>
<ModelingTransformation z:Id=""i11"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</ModelingTransformation>
<Name>LinearAxis</Name>
<Tag i:nil=""true"" />
<Transformation z:Id=""i12"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</Transformation>
<Components>
<Component z:Id=""i13"" i:type=""ToolProfile"">
<IsVisible>true</IsVisible>
<ModelingTransformation z:Id=""i14"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</ModelingTransformation>
<Name>Real Holder</Name>
<Tag i:nil=""true"" />
<Transformation z:Id=""i15"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</Transformation>
<Components>
<Component z:Id=""i16"" i:type=""Group"">
<IsVisible>true</IsVisible>
<ModelingTransformation z:Id=""i17"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>6.1209999999999987</M42>
<M43>0</M43>
<M44>1</M44>
</ModelingTransformation>
<Name>Target</Name>
<Tag>DefaultTarget</Tag>
<Transformation z:Id=""i18"">
<Command>I</Command>
<M11>1</M11>
<M12>0</M12>
<M13>0</M13>
<M14>0</M14>
<M21>0</M21>
<M22>1</M22>
<M23>0</M23>
<M24>0</M24>
<M31>0</M31>
<M32>0</M32>
<M33>1</M33>
<M34>0</M34>
<M41>0</M41>
<M42>0</M42>
<M43>0</M43>
<M44>1</M44>
</Transformation>
<Components />
</Component>
</Components>
<HexColor>#6699cc</HexColor>
<Opacity>1</Opacity>
<ProfileType>Holder</ProfileType>
<StickOut>0</StickOut>
<ToolID>d22d6e4c-be03-471e-bcac-0e5d12852fb2</ToolID>
</Component>
</Components>
<DirectionX>0</DirectionX>
<DirectionY>1</DirectionY>
<DirectionZ>0</DirectionZ>
<InitialPosition>0</InitialPosition>
<Max>2.5</Max>
<MaxFeedrate z:Id=""i19"">
<Inch i:nil=""true"" />
<Metric i:nil=""true"" />
</MaxFeedrate>
<Min>0.75</Min>
<Position>1.3118700546473194</Position>
<AxisType>Y</AxisType>
</Component>
</Components>
<HexColor>#6699cc</HexColor>
<Opacity>1</Opacity>
<ProfileType>Tool</ProfileType>
<StickOut>1.3118700546473194</StickOut>
<ToolID>00000000-0000-0000-0000-000000000000</ToolID>
</Component>
</Components>
<Control></Control>
<Family></Family>
<IsMetric>false</IsMetric>
<MachineToolType>VerticalLathe</MachineToolType>
<Manufacturer></Manufacturer>
<Model></Model>
<Series></Series>
<SubModel></SubModel>
</Machine>",
-----Original Message-----
From: [email protected] [mailto:[email protected]]
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 <[email protected]>
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 above number means that sqlite3_column_text allocated exactly 8960
bytes for the text it returned. So whatever you use to define that returned
text is incomplete gives you incorrect information.
Pavel
_______________________________________________
sqlite-users mailing list
[email protected]
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
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users