Files
c-prime/application/source/examples/example.sqlite3.c
2025-11-17 10:28:09 +01:00

154 lines
2.2 KiB
C

#include "../sqlite.h"
#include "../array.h"
#include "../console.h"
#include "../street.h"
#include "../user.h"
#include <time.h>
void main() {
// sqlite * sql = new sqlite("./database/users.sqlite");
sqlite * sql = new sqlite(":memory:");
sql->selectModel( "user" );
sql->createTable();
char * names[20] = { "piet", "gurbe", "siebe", "gerben", "twain", "piet", "gurbe", "siebe", "gerben", "twain", "piet", "gurbe", "siebe", "gerben", "twain" };
clock_t tic = clock();
array * usersInsertArray = new array();
for (int i = 0; i <10; ++i) //20000
{
char * name = names[i];
struct user * userInstance = new user();
userInstance->id = i;
userInstance->username = name;
userInstance->userlevel = 3;
userInstance->hash = "12345";
usersInsertArray.add( userInstance );
//sql->addRow( userInstance );
}
sql->addRows( usersInsertArray );
clock_t toc = clock();
printf("Multiply: %f seconds, rows: %i\n", (double)( toc - tic ) / CLOCKS_PER_SEC, 10000);
array * usersA = sql->fetchRows( "SELECT * FROM user" );
//user * firstUser = new user();
user * firstUser = usersA->get( 1 );
//firstUser->id =10;
firstUser->username = "updated";
firstUser->userlevel = 1111;
firstUser->hash = "new hash";
console->log( "??", firstUser, "Yeey console.log workswith , , " );
sql->update( firstUser );
printf("before log\n\n");
array * users = sql->fetchRows( "SELECT * FROM user " );
int userCount = users->total;
printf("added rows: %i\n", userCount);
console->createHorisontalLine();
printf("\e[1m");
printf(" ");
printf("%-20s", "id" );
printf("%-30s", "username" );
printf("%-20s", "userLevel" );
printf("%-30s", "Hash");
printf("\e[m");
printf("\n");
console->createHorisontalLine();
printf("users: %i\n", userCount);
for (int i = 0; i < userCount; ++i)
{
struct user * userInstance = users->get( i );
userInstance->id;
userInstance->username;
printf(" ");
printf("%-20i", userInstance->id);
printf("%-30s", userInstance->username);
printf("%-20i", userInstance->userlevel);
printf("%-30s", userInstance->hash);
printf( "\n" );//%-30s
}
sql->free();
console->createHorisontalLine();
}
void abort() {
}