· 8 years ago · Jun 24, 2018, 03:40 PM
1 if (!vcp->vc_result_file || (vcp->vc_verbose > 0)) {
2
3
4 wallet[i]=(char*)malloc(35); // alloc memory for wallet
5 strcpy(wallet[i], addr_buf); // copy the wallet to array
6 privkey[i]=(char*)malloc(256); // alloc memory for privkey
7 strcpy(privkey[i], privkey_buf); // copy the wallet to array
8
9
10 i++;
11 vi++;
12
13
14 // go into db func
15 if (i >= 50000) {
16 printf("\r\rTotal records going in: %d", vi);
17 fflush( stdout );
18 fflush( stdout );
19
20 sqlite3_stmt *stmt;
21 int rc;
22 char *zErrMsg = NULL;
23
24 sqlite3 *db;
25 char *query = NULL;
26
27
28 /* Open database btc_dataBase.db*/
29 rc = sqlite3_open_v2("really.db", &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_CONFIG_MULTITHREAD, NULL);
30 if (rc) {
31 fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
32 sqlite3_close(db);
33 exit(EXIT_FAILURE);
34 } else {
35 fprintf(stdout, "\rOpened database successfully");
36 }
37 sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS BITCOIN (ADDRESS TEXT, PRIVKEY TEXT)", NULL, NULL, NULL);
38 sqlite3_exec(db, "BEGIN EXCLUSIVE TRANSACTION;", NULL, NULL, NULL);
39
40 /* Insert generated address into database */
41
42 //Begin loop to mass insert our accumulated keys
43 for(n=0;n<i;n++) {
44 sqlite3_mutex_enter(sqlite3_db_mutex(db)); // Get our own connection
45 //sqlite3_busy_timeout(db, 150); // incase we get locked, slow it down.
46 rewrite: // dont want null
47 asprintf(&query, "INSERT INTO BITCOIN (ADDRESS, PRIVKEY) VALUES('%s','%s')",wallet[n], privkey[n]); //whatevs primal
48 sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); // <---I really want to use this (I finally am!)
49 if (( wallet[n] == "NULL")) goto rewrite;
50 int remaining = vi - processed; // get any remaining records
51 if ((remaining == 0)) goto out; //protect the db
52 /* Execute Insert */
53 rc = sqlite3_exec(db, query, NULL, NULL, &zErrMsg); //do the execution
54 if (rc != SQLITE_OK) {
55 printf("Err %s ",sqlite3_errmsg(db));
56 goto out;
57 } else {
58 processed++; // increase processed because it was a success.
59 fprintf(stdout, "\r\r\rRecord inserted. Total: %d Processed: %d Remaining: %d", vi, processed, remaining);
60 fflush( stdout );
61 fflush( stdout );
62
63 }
64 sqlite3_finalize(stmt);
65 out:
66 free(query); //free the memory
67 sqlite3_mutex_leave(sqlite3_db_mutex(db));
68
69 } //end for
70 sqlite3_exec(db, "COMMIT TRANSACTION;", NULL, NULL, NULL);
71 sqlite3_exec(db, "END TRANSACTION;", NULL, NULL, NULL);
72 if (rc != SQLITE_OK) {
73 fprintf(stderr, "INSERT SQL error: %s\n", zErrMsg);
74 sqlite3_free(zErrMsg);
75 }
76 i = 0; //reset i for next write
77 sqlite3_close(db);
78 printf("\rdone");
79 }
80 }