{"action":"created","issue":{"url":"https://api.github.com/repos/mfragkoulis/PiCO_QL/issues/36","repository_url":"https://api.github.com/repos/mfragkoulis/PiCO_QL","labels_url":"https://api.github.com/repos/mfragkoulis/PiCO_QL/issues/36/labels{/name}","comments_url":"https://api.github.com/repos/mfragkoulis/PiCO_QL/issues/36/comments","events_url":"https://api.github.com/repos/mfragkoulis/PiCO_QL/issues/36/events","html_url":"https://github.com/mfragkoulis/PiCO_QL/issues/36","id":208773301,"number":36,"title":"NG bugs/compilation and linking issues (MSVS 2010 on Win64)","user":{"login":"vitaliyb1","id":22282742,"avatar_url":"https://avatars1.githubusercontent.com/u/22282742?v=3","gravatar_id":"","url":"https://api.github.com/users/vitaliyb1","html_url":"https://github.com/vitaliyb1","followers_url":"https://api.github.com/users/vitaliyb1/followers","following_url":"https://api.github.com/users/vitaliyb1/following{/other_user}","gists_url":"https://api.github.com/users/vitaliyb1/gists{/gist_id}","starred_url":"https://api.github.com/users/vitaliyb1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vitaliyb1/subscriptions","organizations_url":"https://api.github.com/users/vitaliyb1/orgs","repos_url":"https://api.github.com/users/vitaliyb1/repos","events_url":"https://api.github.com/users/vitaliyb1/events{/privacy}","received_events_url":"https://api.github.com/users/vitaliyb1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"mfragkoulis","id":1777974,"avatar_url":"https://avatars2.githubusercontent.com/u/1777974?v=3","gravatar_id":"","url":"https://api.github.com/users/mfragkoulis","html_url":"https://github.com/mfragkoulis","followers_url":"https://api.github.com/users/mfragkoulis/followers","following_url":"https://api.github.com/users/mfragkoulis/following{/other_user}","gists_url":"https://api.github.com/users/mfragkoulis/gists{/gist_id}","starred_url":"https://api.github.com/users/mfragkoulis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mfragkoulis/subscriptions","organizations_url":"https://api.github.com/users/mfragkoulis/orgs","repos_url":"https://api.github.com/users/mfragkoulis/repos","events_url":"https://api.github.com/users/mfragkoulis/events{/privacy}","received_events_url":"https://api.github.com/users/mfragkoulis/received_events","type":"User","site_admin":false},"assignees":[{"login":"mfragkoulis","id":1777974,"avatar_url":"https://avatars2.githubusercontent.com/u/1777974?v=3","gravatar_id":"","url":"https://api.github.com/users/mfragkoulis","html_url":"https://github.com/mfragkoulis","followers_url":"https://api.github.com/users/mfragkoulis/followers","following_url":"https://api.github.com/users/mfragkoulis/following{/other_user}","gists_url":"https://api.github.com/users/mfragkoulis/gists{/gist_id}","starred_url":"https://api.github.com/users/mfragkoulis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mfragkoulis/subscriptions","organizations_url":"https://api.github.com/users/mfragkoulis/orgs","repos_url":"https://api.github.com/users/mfragkoulis/repos","events_url":"https://api.github.com/users/mfragkoulis/events{/privacy}","received_events_url":"https://api.github.com/users/mfragkoulis/received_events","type":"User","site_admin":false}],"milestone":null,"comments":5,"created_at":"2017-02-20T03:04:36Z","updated_at":"2017-04-23T17:47:26Z","closed_at":null,"body":"Hi Marios,\r\n\r\n0) The issue (in latest **ng** branch) is as follows:\r\n\r\n**register_table** calls **pico_ql_exec_query**, for which the body is missing (though it is declared in **<pico_ql.h>**).\r\n\r\n1) **strsep** does not exist on Windows, I used the following port:\r\n\r\n```\r\n#ifdef _WIN32\r\nchar* strsep(char** stringp, const char* delim)\r\n{\r\n  char* start = *stringp;\r\n  char* p;\r\n  p = (start != NULL) ? strpbrk(start, delim) : NULL;\r\n  if (p == NULL)\r\n  {\r\n    *stringp = NULL;\r\n  }\r\n  else\r\n  {\r\n    *p = '\\0';\r\n    *stringp = p + 1;\r\n  }\r\n  return start;\r\n}\r\n#endif // _WIN32\r\n\r\n```\r\n2) **typeof** does not exist on Windows, I used the following defines:\r\n```\r\n#ifdef _WIN32\r\n#define TYPEOF(x) decltype(x)\r\n#pragma warning(disable:4244)\r\n#pragma warning(disable:4267)\r\n#else\r\n#define TYPEOF(x) typeof(x)\r\n#endif // _WIN32\r\n```\r\n3) In C code on Windows, declaring arrays, indexed by a variable is forbidden.\r\nHere's the fix I applied in multiple places:\r\n```\r\n#ifdef _WIN32\r\n  char *copy = (char*)malloc(length);\r\n#else\r\n  char copy[length];\r\n#endif /* _WIN32 */\r\n```\r\n\r\nOf course, you have to later call **free()**.\r\n\r\n4) In order to not depend on Swill at all, I had to put the code in **pico_ql_swill.c, pico_ql_swill.h, pico_ql_swill_access_func.h**\r\n\r\nunder\r\n\r\n```\r\n#ifdef HAS_SWILL\r\n#endif // HAS_SWILL\r\n\r\n```\r\n5) **pthread_t** does not exist on Windows. Since I only need PICO_QL_SINGLE_THREADED, there should be the version, not using *pthread_t*, e.g.\r\n\r\n```\r\n#ifdef PICO_QL_SINGLE_THREADED\r\n/* The API with user application code. Creates the PiCO_QL thread. */\r\nint pico_ql_name(init)(const char **pragmas, int npragmas, int port) \r\n#else\r\nint pico_ql_name(init)(const char **pragmas, int npragmas, int port, pthread_t *sqlite_thread) \r\n#endif /* PICO_QL_SINGLE_THREADED */\r\n\r\n```\r\n\r\n6) There is bug in **pico_ql_directives_utils_cpp.erb**, below is the fixed code:\r\n\r\n```\r\n  queries = (const char **)sqlite3_malloc(sizeof(const char *) * ( <%= (@tables.length + views_length).to_s %> + conf->npragmas ) );\r\n  if (queries == NULL) {\r\n    printf(\"Out of memory\\n\");\r\n    return NULL;\r\n  }\r\n  sqlite_names = (const char **)sqlite3_malloc(sizeof(const char *) * ( <%= (@tables.length + views_length).to_s %> + conf->npragmas ) );\r\n\r\n```\r\nNote the npragmas should be multipled by sizeof(const char*).\r\n\r\nBest regards,\r\nVitaly\r\n"},"comment":{"url":"https://api.github.com/repos/mfragkoulis/PiCO_QL/issues/comments/296466073","html_url":"https://github.com/mfragkoulis/PiCO_QL/issues/36#issuecomment-296466073","issue_url":"https://api.github.com/repos/mfragkoulis/PiCO_QL/issues/36","id":296466073,"user":{"login":"vitaliyb1","id":22282742,"avatar_url":"https://avatars1.githubusercontent.com/u/22282742?v=3","gravatar_id":"","url":"https://api.github.com/users/vitaliyb1","html_url":"https://github.com/vitaliyb1","followers_url":"https://api.github.com/users/vitaliyb1/followers","following_url":"https://api.github.com/users/vitaliyb1/following{/other_user}","gists_url":"https://api.github.com/users/vitaliyb1/gists{/gist_id}","starred_url":"https://api.github.com/users/vitaliyb1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vitaliyb1/subscriptions","organizations_url":"https://api.github.com/users/vitaliyb1/orgs","repos_url":"https://api.github.com/users/vitaliyb1/repos","events_url":"https://api.github.com/users/vitaliyb1/events{/privacy}","received_events_url":"https://api.github.com/users/vitaliyb1/received_events","type":"User","site_admin":false},"created_at":"2017-04-23T17:47:26Z","updated_at":"2017-04-23T17:47:26Z","body":"Hi Marios, \r\n\r\nI have downloaded new code and tried it (with *PICO_QL_SINGLE_THREADED* defined).\r\n*pico_ql_exec.cpp* contains the following declaration: \r\n\r\n`extern sqlite3 *db;`\r\n\r\nHowever, *db* is not defined anywhere in the library. Therefore, linking with the library fails.\r\nIf I declare  sqlite3 *db in my code, it does not help much, since it looks like library does not store the pointer to database anywhere:\r\n`\r\n#ifdef PICO_QL_SINGLE_THREADED\r\nint pico_ql_name(init)(const char **pragmas, int npragmas, int port) {\r\n#else\r\nint pico_ql_name(init)(const char **pragmas, int npragmas, int port, pthread_t *sqlite_thread) {\r\n#endif\r\n  //int *portN = new int(port);\r\n  sqlite3 *db = NULL;\r\n  /**\r\n   * Virtual table schema will be in-memory and will not\r\n   * persist. Views can be included in the DSL\r\n   */\r\n  int re = sqlite3_open(\":memory:\", &db);\r\n  if (re) {\r\n    printf(\"can't open database\\n\");\r\n    sqlite3_close(db);\r\n    return SQLITE_ERROR;\r\n  }\r\n  config *conf = new config();\r\n  conf->db = db;\r\n  conf->port = port;\r\n  conf->pragmas = pragmas;\r\n  conf->npragmas = npragmas;\r\n#ifndef PICO_QL_SINGLE_THREADED\r\n  re = (int)(long)pthread_create(sqlite_thread, NULL, thread_sqlite, (void *)conf);\r\n#else\r\n  re = (int)(long)thread_sqlite((void *)conf);\r\n#endif\r\n  return SQLITE_OK;\r\n}\r\n} // extern C\r\n} // namespace picoQL\r\n`\r\n\r\nThis should be solved until I move further.\r\n\r\nThank you,\r\nVitaly\r\n"}}
{"actor":{"display_login":"vitaliyb1"}}