Skip to content
Permalink
Browse files

WIP: Connect to registry db and add a snapshot in snapshots table

Tried running `port snapshot` and check if it is able to connect to
db (passing from Tcl to cregistry) and insert a new record there
  • Loading branch information
umeshksingla authored and neverpanic committed Jun 25, 2017
1 parent 9d67b3c commit 9ba669413244a95ceca942eead3483acfe722822
Binary file not shown.
@@ -1310,6 +1310,70 @@ int reg_entry_depends(reg_entry* entry, char* name, reg_error* errPtr) {
return result;
}

void test_call_c() {
printf("inside cregsitry\n");
}

reg_entry* reg_snapshot_create(reg_registry* reg, char* note, reg_error* errPtr) {

printf("inside cregsitry sn cr\n");

sqlite3_stmt* stmt = NULL;
reg_entry* entry = NULL;
char* query = "INSERT INTO registry.snapshots (note) VALUES (?)";

if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
&& (sqlite3_bind_text(stmt, 1, note, -1, SQLITE_STATIC)
== SQLITE_OK)) {
int r;
Tcl_HashEntry* hash;
int is_new;
do {
r = sqlite3_step(stmt);
switch (r) {
case SQLITE_DONE:
entry = malloc(sizeof(reg_entry));
if (entry) {
entry->id = sqlite3_last_insert_rowid(reg->db);
entry->reg = reg;
entry->proc = NULL;
hash = Tcl_CreateHashEntry(&reg->open_entries,
(const char*)&entry->id, &is_new);
Tcl_SetHashValue(hash, entry);

printf("%lld\n", entry->id);

// TODO: move this functions to a different file
int ports_saved = snapshot_store_ports(reg, entry, errPtr);

switch (ports_saved) {
case 1:
// TODO: pass the custom SUCCESS messages
break;
case 0:
reg_sqlite_error(reg->db, errPtr, query);
break;
}

}
break;
case SQLITE_BUSY:
break;
default:
reg_sqlite_error(reg->db, errPtr, query);
break;
}
} while (r == SQLITE_BUSY);
} else {
reg_sqlite_error(reg->db, errPtr, query);
}
if (stmt) {
sqlite3_finalize(stmt);
}
printf("done with the snapshot\n");
return entry;
}

/**
* Fetches a list of all open entries.
*
@@ -94,6 +94,9 @@ int reg_entry_dependencies(reg_entry* entry, reg_entry*** dependencies,
reg_error* errPtr);
int reg_entry_depends(reg_entry* entry, char* name, reg_error* errPtr);

void test_call_c();
reg_entry* reg_snapshot_create(reg_registry* reg, char* note, reg_error* errPtr);

int reg_all_open_entries(reg_registry* reg, reg_entry*** entries);

#endif /* _CENTRY_H */
@@ -199,7 +199,7 @@ int create_tables(sqlite3* db, reg_error* errPtr) {
/* snapshots table */
"CREATE TABLE registry.snapshots ("
"id INTEGER PRIMARY KEY"
", created_at DATETIME"
", created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL"
", note TEXT"
")",
"CREATE INDEX registry.snapshot ON snapshots(id)",
@@ -8,6 +8,7 @@
package provide snapshot 1.0

package require macports 1.0
package require registry 1.0

namespace eval snapshot {

@@ -19,5 +20,15 @@ namespace eval snapshot {
# Returns:
# None
puts "Still being developed"
#registry::entry addsnapshot
foreach port [registry::entry imaged] {
puts [$port name]
}

registry::entry testcall
set a [registry::entry snapshot "testsnapshot"]
puts $a
puts done

}
}
@@ -518,6 +518,39 @@ static int entry_owner(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]) {
}
}

static int test_call(){
printf("inside registry2.0\n");
test_call_c();
printf("done here\n");
return TCL_OK;
}

static int snapshot_create(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]) {

printf("inside 2.0 entry\n");

reg_registry* reg = registry_for(interp, reg_attached);
if (objc > 3) {
Tcl_WrongNumArgs(interp, 2, objv, "snapshot ?note?");
return TCL_ERROR;
} else if (reg == NULL) {
return TCL_ERROR;
} else {
char* note = Tcl_GetString(objv[2]);
reg_error error;
/* may be a new datatype for snapshot */
reg_entry* new_snaphot = reg_snapshot_create(reg, note, &error);
if (new_snaphot != NULL) {
Tcl_Obj* result;
if (entry_to_obj(interp, &result, new_snaphot, NULL, &error)) {
Tcl_SetObjResult(interp, result);
return TCL_OK;
}
}
return registry_failed(interp, &error);
}
}

typedef struct {
char* name;
int (*function)(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]);
@@ -534,6 +567,9 @@ static entry_cmd_type entry_cmds[] = {
{ "imaged", entry_imaged },
{ "installed", entry_installed },
{ "owner", entry_owner },
/* test call */
{ "testcall", test_call },
{ "snapshot", snapshot_create},
{ NULL, NULL }
};

0 comments on commit 9ba6694

Please sign in to comment.
You can’t perform that action at this time.