I have the following code :
sqlite *sql = new sqlite; // create a new sqlite object.
const char *dbFile = "database.db"; // sqlite database file.
sql->open(dbFile); // open the connection.
sql->query("SELECT * FROM categories"); // make a query.
int numRows = sql->numRows(); // get the number of rows.
const unsigned char *result[numRows]; // an array to store data that will be brought in from the database.
int index = 0; // counter
while(sql->fetch() != SQLITE_DONE){
// store the data into an array
result[index] = sql->getValue("name");
index++;
// print the data directly without storing in an array
cout << sql->getValue("name") << endl;
}
sql->close();
// print the content of the `result` array.
for(int i=0;i<numRows;i++){
cout << result[i] << endl;
}
The result:
Notice:
The method sql->getValue("name");
return const unsigned char*
data.
As you seen in the result image, why when print the data directly, appear without problems, while when print the same data stored in the array does not appear ?
Aucun commentaire:
Enregistrer un commentaire