如何使用struct创建数据库表

时间:2014-06-26 18:35:50

标签: c database memory-management structure firebird

我正在与firebird数据库进行c接口。详情如下。 在,database.c文件中,我初始化了createTable函数和包含约束和数据类型的Folder_table结构。我想知道如何读取结构并将其保存为数据库表。 (我可以用sprintf做些什么吗?)

**database.c:**
void* CreateTable(char *tableName, uint rows)
{
    int error   = 0;
    void *table;

    //// Allocate table
    table = Allocate(GetTableSize(tableName)*rows);

    //// List table pointers
    for(uint rowNumber=0; rowNumber < rows; rowNumber++)
    {
        //// Add code to Connect linked list row pointers
    }

    return error;
}

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

} Folder_Table;

**main.c:**
#include <stdio.h>
#include<string.h>

char  Query[] = "SELECT * FROM Folder_Table WHERE ID = 3";
int main(int argc, char *argv[])
{

    Folder_Table *myTable;
    myTable = CreateTable("Folder_Table", ONE_ROW);

}

这里,如何读取结构并将传递的值保存为数据库表?你能帮帮我吧吗?

0 个答案:

没有答案