maintenance.c
/* add one item to table whose file name is the argument */
add one item to table whose file name is the argument
add one item to table whose file name is the argument
int insert_to_database(char name[MAX_CHARS])
{
    sqlite3 *db;
    int rc = sqlite3_open_v2("items.db", &db, SQLITE_OPEN_READWRITE, NULL);
    if (rc) 
    {
        printf("Cannot open database: %s\n", sqlite3_errmsg(db));
        return 1;
    }
    char min[4] = {'\0'}, max[4] = {'\0'}, type[4] = {'\0'};
    printf("%s\n", name);
    char *pos;
    printf("Type the coldest temperature appropriate for this article of clothing\n");
    scanf("%3s", min);
    if ((pos = strchr(min, '\n')) != NULL)
        *pos = '\0';
    printf("Type the warmest temperature appropriate for this article of clothing\n");
    scanf("%3s", max);
    if ((pos = strchr(max, '\n')) != NULL)
        *pos = '\0';
    char q[] = "To properly categorize this item assign it a layer value."
               "For tops"
               " 1 if this can be worn below another layer "
               " for example a tee shirt."
               " 2 if this is worn by itself."
               " 3 if this must be worn above another layer "
               " e.g. a jacket."
               " 0 for bottoms.";
    printf("%s\n", q);
    scanf("%3s", type);
    if ((pos = strchr(type, '\n')) != NULL)
        *pos = '\0';
    sqlite3_stmt *stmt;
    char *insert_query = sqlite3_mprintf("INSERT INTO clothing"
                                         "(name, days_passed, coldest_t, warmest_t, layer_value) "
                                         "VALUES"
                                         "('%s', 0, %s, %s, %s);",
                                         name, min, max, type);
    rc = sqlite3_prepare_v2(db, insert_query, -1, &stmt, NULL);
    if (rc != SQLITE_OK) 
    {
        printf("error: %s\n", sqlite3_errmsg(db));
        return 0;
    }
    rc = sqlite3_step(stmt);
    sqlite3_finalize(stmt);
    sqlite3_close(db);
    return 0;
}
int insert_to_database ( char name [ MAX_CHARS ] ) { sqlite3 * db ; int rc = sqlite3_open_v2 ( " " , & db , SQLITE_OPEN_READWRITE , NULL ) ; if ( rc ) { printf ( " \n " , sqlite3_errmsg ( db ) ) ; return 1 ; } char min [ 4 ] = { ' \0 ' } , max [ 4 ] = { ' \0 ' } , type [ 4 ] = { ' \0 ' } ; printf ( " \n " , name ) ; char * pos ; printf ( " \n " ) ; scanf ( " " , min ) ; if ( ( pos = strchr ( min , ' \n ' ) ) != NULL ) * pos = ' \0 ' ; printf ( " \n " ) ; scanf ( " " , max ) ; if ( ( pos = strchr ( max , ' \n ' ) ) != NULL ) * pos = ' \0 ' ; char q [ ] = " " " " " " " " " " " " " " " " ; printf ( " \n " , q ) ; scanf ( " " , type ) ; if ( ( pos = strchr ( type , ' \n ' ) ) != NULL ) * pos = ' \0 ' ; sqlite3_stmt * stmt ; char * insert_query = sqlite3_mprintf ( " " " " " " " " , name , min , max , type ) ; rc = sqlite3_prepare_v2 ( db , insert_query , -1 , & stmt , NULL ) ; if ( rc != SQLITE_OK ) { printf ( " \n " , sqlite3_errmsg ( db ) ) ; return 0 ; } rc = sqlite3_step ( stmt ) ; sqlite3_finalize ( stmt ) ; sqlite3_close ( db ) ; return 0 ; }
add one item to table whose file name is the argument
add one item to table whose file name is the argument
/* collect auxillary table fields.
    Do absolutely no
    sanitizing 
    type checking 
    ref https://stackoverflow.com/a/2693826*/ /* simple number scheme in order to make quick edits to the
    classification structure */ //printf("%s\n", type); /* will fail silently if I try to insert a
    duplicate name */ //printf("%s\n", insert_query);