数据结构作业:传输数据的增删改

这个博客展示了如何使用C语言通过SQLite3库进行数据库操作,包括创建表格、向表格中插入数据、更新数据和删除数据。通过示例代码详细解释了每个操作的实现过程。
摘要由CSDN通过智能技术生成

#include <stdio.h>
#include <sqlite3.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
int  do_insert(sqlite3 *db,char *excl);//向表格中增加,传参为句柄指针和excl表格名
int do_updata(sqlite3 * db,char *excl);//改。参数为句柄指针和表格名,通过Id来修改
int  do_delete(sqlite3 *db,char *excl);//删除,传参为创建的表格
int main(int argc, const char *argv[])
{
    if(argc<2)
    {
        printf("没有输入要创建打开的数据库\n");
        return -1;
    }
    //打开创建一个数据库
    sqlite3 *db =NULL;//打开创建出来的句柄指针
    if(sqlite3_open(argv[1],&db)!=SQLITE_OK<0)
    {
        fprintf(stderr,"line = __%d__,sqlite3_open = %s\n",__LINE__,sqlite3_errmsg(db));
        fprintf(stderr,"line = __%d__,sqlite3_open = %d\n",__LINE__,sqlite3_errcode(db));
        return 0;
    }
    printf("database open success\n");

    //创建表格,sqlite3_exec作用让c执行创建,同时将主键设置为id
    char sql[128]="";//c中要执行的语句
    char excl[23]="";//创建出来的表格名
    printf("请输入要创建的表格名->>");
    fgets(excl,sizeof(excl),stdin);
    excl[strlen(excl)-1]=0;
    sprintf(sql,"create table if not exists %s (id int PRIMARY key ,name char ,score float);",excl);
    char * errmsg=NULL;

    if(sqlite3_exec(db,sql,NULL,NULL,&errmsg)<0)
    {
        fprintf(stderr,"line = __%d__,sqlite3_open = %s\

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值