Advertisement
Guest User

Untitled

a guest
May 27th, 2017
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. diff --git a/dbf2mysql.c b/dbf2mysql.c
  2. index 69f84b8..039df3d 100644
  3. --- a/dbf2mysql.c
  4. +++ b/dbf2mysql.c
  5. @@ -30,6 +30,7 @@ char *dbase = "test";
  6. char *table = "test";
  7. char *pass = NULL;
  8. char *user = NULL;
  9. +char *charset = "latin1";
  10.  
  11. char *subarg = NULL;
  12. char *flist = NULL;
  13. @@ -82,7 +83,7 @@ void usage(void){
  14. printf("usage: dbf2mysql [-h hostname] [-d dbase] [-t table] [-p primary key]\n");
  15. printf(" [-o field[,field]] [-s oldname=newname[,oldname=newname]]\n");
  16. printf(" [-i field[,field]] [-c] [-f] [-F] [-n] [-r] [-u|-l] \n");
  17. - printf(" [-v[v]] [-x] [-q] [-P password] [-U user] dbf-file\n");
  18. + printf(" [-v[v]] [-x] [-q] [-P password] [-U user] [-C charset] dbf-file\n");
  19. }
  20.  
  21. /* patch by Mindaugas Riauba <minde@pub.osf.lt> */
  22. @@ -602,7 +603,7 @@ int main(int argc, char **argv)
  23.  
  24. primary[0] = '\0';
  25.  
  26. - while ((i = getopt(argc, argv, "xqfFrne:lucvi:h:p:d:t:s:o:U:P:")) != EOF) {
  27. + while ((i = getopt(argc, argv, "xqfFrne:lucvi:h:p:d:t:s:o:U:P:C:")) != EOF) {
  28. switch (i) {
  29. case 'P':
  30. pass = (char *)strdup(optarg);
  31. @@ -610,6 +611,9 @@ int main(int argc, char **argv)
  32. case 'U':
  33. user = (char *)strdup(optarg);
  34. break;
  35. + case 'C':
  36. + charset = (char *)strdup(optarg);
  37. + break;
  38. case 'x':
  39. express=1;
  40. break;
  41. @@ -742,6 +746,14 @@ int main(int argc, char **argv)
  42. dbf_close(&dbh);
  43. exit(1);
  44. }
  45. + if (verbose > 2) {
  46. + printf("Setting charset to '%s'\n", charset);
  47. + }
  48. + sprintf(query, "SET NAMES %s", charset);
  49. + mysql_query(SQLsock, query);
  50. + free(query);
  51. +
  52. +
  53. /* Substitute field names */
  54. do_onlyfields(flist, dbh);
  55. do_substitute(subarg, dbh);
  56. diff --git a/mysql2dbf.c b/mysql2dbf.c
  57. index 58304ba..3e62d2f 100644
  58. --- a/mysql2dbf.c
  59. +++ b/mysql2dbf.c
  60. @@ -20,6 +20,7 @@ char *dbase = NULL;
  61. char *table = NULL;
  62. char *pass = NULL;
  63. char *user = NULL;
  64. +char *charset = "latin1";
  65.  
  66. inline void strtoupper(char *string);
  67. inline void strtolower(char *string);
  68. @@ -41,7 +42,7 @@ inline void strtolower(char *string) {
  69.  
  70. void usage(void) {
  71. printf("mysql2dbf %s\n", VERSION);
  72. - printf("usage:\tmysql2dbf [-h host] [-u | -l] [-v[v]]\n");
  73. + printf("usage:\tmysql2dbf [-h host] [-u | -l] [-v[v]] [-C charset]\n");
  74. printf("\t\t\t[-q query] [-P password] [-U user] -d dbase -t table dbf-file\n");
  75. }
  76.  
  77. @@ -51,6 +52,7 @@ int main(int argc, char **argv) {
  78. extern int optind;
  79. extern char *optarg;
  80. char *query = NULL;
  81. + char *char_query = NULL;
  82.  
  83. dbhead *dbh;
  84. field *rec;
  85. @@ -101,6 +103,9 @@ int main(int argc, char **argv) {
  86. case 'U':
  87. user = (char *)strdup(optarg);
  88. break;
  89. + case 'C':
  90. + charset = (char *)strdup(optarg);
  91. + break;
  92. case ':':
  93. usage();
  94. printf("Missing argument!\n");
  95. @@ -170,6 +175,13 @@ int main(int argc, char **argv) {
  96. exit(1);
  97. }
  98.  
  99. + if (verbose > 2) {
  100. + printf("Setting charset to '%s'\n", charset);
  101. + }
  102. + sprintf(char_query, "SET NAMES %s", charset);
  103. + mysql_query(SQLsock, char_query);
  104. + free(char_query);
  105. +
  106. if (verbose > 1) {
  107. printf("Sending query\n");
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement