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