OwnedArray of one Array


#1

Hi,

I have one situation that i cannot solve.

I have a struct like this:

struct ZonesTBL
{
int ID;
int Terminal;
String Description;
int InitialValue;
int FinalValue;
int ItemPrice;
String Employees;
};

That will holds the information of a table row.

And a function:

OwnedArray<ZonesTBL> getAllZones()
{
ZonesTBL ZonesData;
OwnedArray<ZonesTBL> ZonesArray;

(...)

int res = 0;
while ((res = sqlite3_step(query)) == SQLITE_ROW)
{
Logger::outputDebugString("**DB Zones - Found one");
ZonesData.ID = (intptr_t)sqlite3_column_text(query, 0);
ZonesData.Terminal = (intptr_t)sqlite3_column_text(query, 1);
ZonesData.Description = (char*)sqlite3_column_text(query, 2);
ZonesData.InitialValue = (intptr_t)sqlite3_column_text(query, 3);
ZonesData.FinalValue = (intptr_t)sqlite3_column_text(query, 4);
ZonesData.ItemPrice = (intptr_t)sqlite3_column_text(query, 5);
ZonesData.Employees = (char*)sqlite3_column_text(query, 6);

ZonesArray.add(&ZonesData);
} 

(...)

return ZonesArray; }

But I cannot add the struct ZonesData to my array. What is wrong and how to solve it ?

Thanks,

Paulo

as

 


#2

I'm sure most of us don't mind an occassionaly c++ question, but so many of your issue seem to relvove around you not understand the language. The main problem I see with this code relates to 'scope'. Please go spend some time leanring about this. The main problem with your code is that both the ZonesArray and ZoneData are only valid during the lifetime of the getAllZones() function. Please go study more about scoping and pointers.

 

-cpr
 


#3

Thanks