Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » SQlite3: my problem or bug?
SQlite3: my problem or bug? [message #28471] Thu, 02 September 2010 20:04 Go to next message
mubeta is currently offline  mubeta
Messages: 77
Registered: October 2006
Member
Hi all,

The fact: the following function, copied as is, is derived from an old work, that is working as well.
void App::ListDbSave()
{
  String fName;
  bool selection;
  int total, partial;
 
	FileSelector fs;
	fs.Type("S7prj files", "*.s7prj").DefaultExt("s7prj").ActiveDir(GetHomeDirectory());
	if(!fs.ExecuteSaveAs(t_("Save as.."))) 
	{
		return;
	}
	fName = fs;
  
  selection = false;
  total = 0;
  for(int i = 0; i < objLayListDB.gListDB.GetCount(); i++)
  {
    if(objLayListDB.gListDB.Get(i, 0) == true) 
    {
    	selection = true;
    	total += (int)objLayListDB.gListDB.Get(i, 2);
    }
  }
  if(selection == false)
  {
    Exclamation(t_("Select the DB!"));
    return;
  }
  
	Sqlite3Session db1;
	if(!db1.Open(fName)) 
	{
		Exclamation("Can't create the project file");
		return;
	}

  Sql sql(db1);
  sql.Execute("DROP TABLE Project");
  sql.Execute("CREATE TABLE Project (Id integer primary key, MemType integer, DbNum integer, Start integer, Length integer, Buff blob)");

  partial = 0;
	if (StartConnection()) 
	{
    Progress p;
	  p.Title(t_("Working.."));
	  p.AlignText(Ctrl::LEFT);	  
	  p.Set(partial, total);		  
	  
	  for(int i = 0; i < objLayListDB.gListDB.GetCount(); i++)
	  {
      if(objLayListDB.gListDB.Get(i, 0) == true)
      {
			  daveDbNum = (int)objLayListDB.gListDB.Get(i, 1);
			  daveStart = 0;
			  daveLen = (int)objLayListDB.gListDB.Get(i, 2);
			  daveArea = daveDB;
			  daveMem1.valMemType = daveArea;
			  daveMem1.valDbNum = daveDbNum;		  
			  daveMem1.valLen = daveLen;
			  daveMem1.valStart = daveStart;		
			  daveMem1.strValues.Clear();
			  
				while ( (int)daveLen >= 222 )
				{
					daveRes = libnodave().daveReadBytes(dc, daveArea, daveDbNum, daveStart, 222, NULL);
					if (0 == daveRes) 
					{
					  daveMem1.strValues.Cat(dc->resultPointer, dc->AnswLen);	
					  daveLen -= dc->AnswLen;
					  daveStart += dc->AnswLen;
					}
					else 
					{
						Exclamation(t_("Get failed! ") + Format("%d", daveRes), 
						            callback(CallHelp), 
						            "Docs/resErrorCodes");
						return;
					}
					partial += (int)daveMem1.valLen - daveLen;
					p.Set(partial, total);
				}
				if ((int)daveLen > 0)
				{
					daveRes = libnodave().daveReadBytes(dc, daveArea, daveDbNum, daveStart, daveLen, NULL);
					if (0 == daveRes) 
					{
					  if (dc->AnswLen > 0) daveMem1.strValues.Cat(dc->resultPointer, dc->AnswLen);
					}  
					else 
					{
						Exclamation(t_("Get failed! ") + Format("%d", daveRes), 
						            callback(CallHelp), 
						            "Docs/resErrorCodes");
						return;
					}
					partial += (int)daveMem1.valLen - daveLen;					
				}
		    p.Set(partial, total);
		    
		    RLOGHEXDUMP(daveMem1.strValues, daveMem1.strValues.GetCount());

				daveMem1.timFileTime = GetSysTime();
			  
			  // This way work also with binary values
			  sql*SqlInsert("Project")("Id", i)("DbNum", daveDbNum)("Start", daveStart)("Length", daveLen)("Buff", daveMem1.strValues);
		  }
	  }
	  p.Close();
	  PromptOK(t_("Done."));
	  CloseConnection();
	}
	
  // Delete *.sql files
  FindFile ff(ConfigFile("*.sql"));
  do
  {
    if(ff.IsFile()) FileDelete(ConfigFile(ff.GetName()));
  } while(ff.Next());

	db1.Close();
	 
  return;
}


The problem is here:
		    RLOGHEXDUMP(daveMem1.strValues, daveMem1.strValues.GetCount());

				daveMem1.timFileTime = GetSysTime();
			  
			  // This way work also with binary values
			  sql*SqlInsert("Project")("Id", i)("DbNum", daveDbNum)("Start", daveStart)("Length", daveLen)("Buff", daveMem1.strValues);



The <<for>> loop, depending on some user setting, store in the var: daveMem1.strValues some binary data and, at the end of the loop there is the SqlInsert statement for store all in the own DB.

Problem: sometime, teh stored data in the database is not complete, regarding the field named "Buff". In the source code I am looking what happen using RLOGHEXDUMP. Following the log results as is:
* L:\Epd\EpdSviluppo\Developing\Exe\S7DataArchiver\S7DataArchiver.exe 02.09.2010 19:23:10, user: Administrator

Memory at 0012BB1C, size 0xA = 10
    +0 0x0012BB1C 01 02 03 04 05 06 07 08 09 0A                       ..........      
Memory at 00C20198, size 0x5C = 92
    +0 0x00C20198 3F 03 12 6F 00 00 00 01 00 00 00 00 00 00 00 02     ?..o............
   +16 0x00C201A8 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 00     ................
   +32 0x00C201B8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00     ................
   +48 0x00C201C8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00     ................
   +64 0x00C201D8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00     ................
   +80 0x00C201E8 00 00 00 00 00 00 00 00 00 00 00 15                 ............    
Memory at 0012BB1C, size 0xC = 12
    +0 0x0012BB1C 0B 0C 0D 0E 0F 10 11 12 13 14 15 00                 ............    
Memory at 0012BB1C, size 0x8 = 8
    +0 0x0012BB1C 16 17 18 19 1A 1B 1C 00                             ........        
Memory at 0012BB1C, size 0x4 = 4
    +0 0x0012BB1C 1D 1E 1F 20                                         ...             
Memory at 0012BB1C, size 0x2 = 2
    +0 0x0012BB1C 21 22                                               !"              



In the second loop the string size is 92 byte (0x5C), and that is correct. In the DB file only the first four bytes are inserted. (Using FireFox plugin and UltraEdit32 for take a look).

I will attach to this post also the log file and the resulting database *.s7prj.

The filed Buff is declared ad "blob" type.

Note that the same function, in the past work very well. I am only replacing the old storage system. (From serialization file to database). I will attach also the file *.s7mem for show that serialization working well.

Second question, regarding an discussed problem: using SqlId("Fieldname"), the "Fieldname" string must be only uppercase, also if in the DB the table is created with lowercase char. Is an U++ limitation or what else?

Thanks.
Re: SQlite3: my problem or bug? [message #28477 is a reply to message #28471] Thu, 02 September 2010 23:12 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 693
Registered: December 2005
Location: Budapest, Hungary
Contributor
I think, you had to escape binary values by calling SqlBinary().
Re: SQlite3: my problem or bug? [message #28478 is a reply to message #28477] Thu, 02 September 2010 23:15 Go to previous messageGo to next message
mubeta is currently offline  mubeta
Messages: 77
Registered: October 2006
Member
How SqlBinary work? I test it a lot of time, but without success.
Can you give me an example?
Re: SQlite3: my problem or bug? [message #28479 is a reply to message #28478] Thu, 02 September 2010 23:53 Go to previous message
zsolt is currently offline  zsolt
Messages: 693
Registered: December 2005
Location: Budapest, Hungary
Contributor
sql * Update(TABLE)
	(FIELD, SqlBinary(binary_value_in_a_string))
	.Where(TABLE_ID == id)
;

[Updated on: Fri, 03 September 2010 00:02]

Report message to a moderator

Previous Topic: Some questions around SQlite3
Next Topic: Issue with sql.execute(const String&)
Goto Forum:
  


Current Time: Fri Mar 29 13:16:14 CET 2024

Total time taken to generate the page: 0.01694 seconds