After changing the code, I got new error in database_definitions.h header file. The error is near the 'extern const Lookup_Table TableLookup[TABLE_COUNT];' and mentioned the error in the code with comments next to it. I also got warning in 'database.c' file near the return &(TableLookup[index]); in the 'Lookup_Table* GetTableMetadata(char *tableName)' function. The error is pasted in the code next to it. Kindly review and help me in solving in this issue.
**database.c**:
const Lookup_Table TableLookup[TABLE_COUNT]=
{
{
.tableName = "Folder_Table",
// .tableInitializer = (void*)&InitFolder_Table,
.tableMemory = sizeof(Folder_Table),
.columns = 5,
.columnNames = {"folderID","field1","field2","field3","field4"}, // Fill out field name metadata
.columnSize = {SIZE_OF(Folder_Table,folderID), SIZE_OF(Folder_Table,field1), SIZE_OF(Folder_Table,field2),
SIZE_OF(Folder_Table,field3), SIZE_OF(Folder_Table,field4)},
.columnType = {TYPE_INT, TYPE_FLOAT, TYPE_INT, TYPE_FLOAT, TYPE_TEXT},
.subTable = {{.tableName = "Item_Table", .pointerOffset = offsetof(Folder_Table,item)},
{.tableName = "nextRow", .pointerOffset = offsetof(Folder_Table, nextRow)},
{.tableName = "lastRow", .pointerOffset = offsetof(Folder_Table, lastRow)},
{.tableName = "\0", .pointerOffset = 0 }},
},
{
.tableName = "Item_Table",
// .tableInitializer = (void*)&InitItem_Table,
.tableMemory = sizeof(Item_Table),
.columns = 4,
.columnNames = {"ItemID\0","FolderID\0","field1\0","field2\0"},
.columnSize = {SIZE_OF(Item_Table,itemID), SIZE_OF(Item_Table,folderID), SIZE_OF(Item_Table,field1),
SIZE_OF(Item_Table,field2)},
.columnType = {TYPE_INT, TYPE_INT, TYPE_TEXT, TYPE_FLOAT},
.subTable = {{.tableName = "nextRow", .pointerOffset = offsetof(Item_Table, nextRow)},
{.tableName = "lastRow", .pointerOffset = offsetof(Item_Table, lastRow)},
{.tableName = "\0", .pointerOffset = 0}},
}
};
//====================================================================================
// Struct Table Initializer and metadata functions
//====================================================================================
//------------------------------------------------------------------------------------
// Find the memory size of a table specified by name
//------------------------------------------------------------------------------------
int GetTableSize(char *tableName)
{
int index;
//// Find function matching function name string
for (index=0 ; index < TABLE_COUNT; index++)
{
if (strcmp(TableLookup[index].tableName, tableName))
{
return(TableLookup[index].tableMemory);
}
}
return 1; // Return error, should this be an exception?
}
//------------------------------------------------------------------------------------
// Return the index of of the table from the table-lookuptable
//------------------------------------------------------------------------------------
Lookup_Table* GetTableMetadata(char *tableName)
{
//// Find function matching function name string
for (int index=0; index < TABLE_COUNT; index++)
{
if (strcmp(TableLookup[index].tableName, tableName))
{
`return &(TableLookup[index]);//error: 'Returning 'const Lookup_Table*(aka 'const structLookup_Table') from a function with result type 'Lookup_Table'(aka 'struct Lookup_Table") discards qualifiers`'
}
}
return 0; // Return error
}
**database.h**:
#ifndef database_h
#define database_h
#include "database_definitions.h"
#define ONE_ROW 1
//====================================================================================
// Function Definitions
//====================================================================================
int SQLOpen(void);
//isc_db_handle SQLGetDatabase(void);
Lookup_Table* GetTableMetadata(char *tableName);
Sub_Table* GetSubTableMetadata(char *tableName, char *subTableName);
#endif
**database_definitions.h**:
#ifndef database_database_h
#define database_database_h
extern const Lookup_Table TableLookup [TABLE_COUNT];
//error:unknown type name 'Lookup_Table'
//====================================================================================
// SQL Table Metadata Structures
//====================================================================================
typedef struct Folder_Table // Table type name gets "_Table" added to the SQLite name
{
//// Fields // Comments are added to seperate the fields, Relationships, and metadata
int folderID; // Fields are added as elements of the type and length listed in SQLite
float field1;
int field2;
float field3;
char field4[40]; // string length '40' is queried from SQLite settings for field
//// Relationships
struct Item_Table *item; // Pointer to the sub-table
struct Folder_Table *nextRow; // Linked List Pointer to the next-row
struct Folder_Table *lastRow; // Linked List Pointer to the last-row
} Folder_Table;
typedef struct Item_Table
{
//// Fields
int itemID;
int folderID;
char field1[32];
float field2;
//// Relationships
Folder_Table *folder;
struct Item_Table *nextRow;
struct Item_Table *lastRow;
} Item_Table;
typedef struct Sub_Table
{
char tableName [TABLE_NAME_LENGTH]; // Sub-table name
int pointerOffset; // Sub-table pointer memory offset in the struct
}Sub_Table;
typedef struct Lookup_Table
{
char tableName [TABLE_NAME_LENGTH]; // Stores table name
void (*tableInitializer)(void *); // Pointer to the initializer function
int tableMemory; // Size of the table memory instance
int columns; // Number of columns in the table
char columnNames[MAX_COLUMNS][COLUMN_NAME_LENGTH]; // Array of column names
int columnSize [MAX_COLUMNS]; // Array of column variable memory sizes
int columnType [MAX_COLUMNS]; // Array of column variable types
Sub_Table subTable [MAX_SUB_TABLES]; // Stores sub-table pointers
}Lookup_Table;
#endif
**main.c**:
#include <stdio.h>
#include "database.h"
int main(int argc, const char * argv[])
{
// SQLOpen();
return 0;
}