--- pxview-0.2.5/src/main.c	2005-08-09 21:57:20.000000000 +0200
+++ pxview-backticks-v2/src/main.c	2016-11-27 08:31:20.860810422 +0100
@@ -1656,7 +1656,7 @@
 
 		/* check if existing table shall be delete */
 		if(deletetable) {
-			str_buffer_print(pxdoc, sbuf, "DROP TABLE %s;\n", tablename);
+			str_buffer_print(pxdoc, sbuf, "DROP TABLE `%s`;\n", tablename);
 			if(SQLITE_OK != sqlite_exec(sql, str_buffer_get(pxdoc, sbuf), NULL, NULL, &sqlerror)) {
 				fprintf(stderr, "%s\n", sqlerror);
 				sqlite_close(sql);
@@ -1671,7 +1671,7 @@
 		/* Output table schema */
 		if(!skipschema) {
 			str_buffer_clear(pxdoc, sbuf);
-			str_buffer_print(pxdoc, sbuf, "CREATE TABLE %s (\n", tablename);
+			str_buffer_print(pxdoc, sbuf, "CREATE TABLE `%s` (\n", tablename);
 			first = 0;  // set to 1 when first field has been output
 			pxf = PX_get_fields(pxdoc);
 			for(i=0; i<PX_get_num_fields(pxdoc); i++) {
@@ -1691,12 +1691,12 @@
 						case pxfTime:
 						case pxfTimestamp:
 						case pxfBytes:
-							str_buffer_print(pxdoc, sbuf, "  %s ", pxf->px_fname);
+							str_buffer_print(pxdoc, sbuf, "  `%s` ", pxf->px_fname);
 							str_buffer_print(pxdoc, sbuf, "%s", get_sql_type(typemap, pxf->px_ftype, pxf->px_flen));
 							first = 1;
 							break;
 						case pxfBCD:
-							str_buffer_print(pxdoc, sbuf, "  %s ", pxf->px_fname);
+							str_buffer_print(pxdoc, sbuf, "  `%s` ", pxf->px_fname);
 							str_buffer_print(pxdoc, sbuf, "%s", get_sql_type(typemap, pxf->px_ftype, pxf->px_fdc));
 							first = 1;
 							break;
@@ -1705,7 +1705,7 @@
 						case pxfFmtMemoBLOb:
 						case pxfGraphic:
 						case pxfOLE:
-							str_buffer_print(pxdoc, sbuf, "  %s ", pxf->px_fname);
+							str_buffer_print(pxdoc, sbuf, "  `%s` ", pxf->px_fname);
 							str_buffer_print(pxdoc, sbuf, "%s", get_sql_type(typemap, pxf->px_ftype, pxf->px_flen));
 							first = 1;
 							break;
@@ -1724,7 +1724,7 @@
 						strrep(pxf->px_fname, ' ', '_');
 						if(first == 1)
 							str_buffer_print(pxdoc, sbuf, ",");
-						str_buffer_print(pxdoc, sbuf, "%s", pxf->px_fname);
+						str_buffer_print(pxdoc, sbuf, "`%s`", pxf->px_fname);
 						first = 1;
 					}
 					pxf++;
@@ -1750,7 +1750,7 @@
 				if(fieldregex == NULL ||  selectedfields[i]) {
 					strrep(pxf->px_fname, ' ', '_');
 					str_buffer_clear(pxdoc, sbuf);
-					str_buffer_print(pxdoc, sbuf, "CREATE INDEX %s_%s_index on %s (%s);", tablename, pxf->px_fname, tablename, pxf->px_fname);
+					str_buffer_print(pxdoc, sbuf, "CREATE INDEX `%s_%s_index` on `%s` (`%s`);", tablename, pxf->px_fname, tablename, pxf->px_fname);
 					if(SQLITE_OK != sqlite_exec(sql, str_buffer_get(pxdoc, sbuf), NULL, NULL, &sqlerror)) {
 						sqlite_close(sql);
 						fprintf(stderr, "%s\n", sqlerror);
@@ -1778,7 +1778,7 @@
 			for(j=0; j<PX_get_num_records(pxdoc); j++) {
 				int offset;
 				str_buffer_clear(pxdoc, sbuf);
-				str_buffer_print(pxdoc, sbuf, "INSERT INTO %s VALUES (", tablename);
+				str_buffer_print(pxdoc, sbuf, "INSERT INTO `%s` VALUES (", tablename);
 				if(PX_get_record(pxdoc, j, data)) {
 					first = 0;  // set to 1 when first field has been output
 					offset = 0;
@@ -2257,11 +2257,11 @@
 
 		/* check if existing table shall be delete */
 		if(deletetable) {
-			fprintf(outfp, "DROP TABLE %s;\n", tablename);
+			fprintf(outfp, "DROP TABLE `%s`;\n", tablename);
 		}
 		/* Output table schema */
 		if(!skipschema) {
-			fprintf(outfp, "CREATE TABLE %s (\n", tablename);
+			fprintf(outfp, "CREATE TABLE `%s` (\n", tablename);
 			first = 0;  // set to 1 when first field has been output
 			pxf = PX_get_fields(pxdoc);
 			for(i=0; i<PX_get_num_fields(pxdoc); i++) {
@@ -2286,12 +2286,12 @@
 						case pxfFmtMemoBLOb:
 						case pxfGraphic:
 						case pxfOLE:
-							fprintf(outfp, "  %s ", pxf->px_fname);
+							fprintf(outfp, "  `%s` ", pxf->px_fname);
 							fprintf(outfp, "%s", get_sql_type(typemap, pxf->px_ftype, pxf->px_flen));
 							first = 1;
 							break;
 						case pxfBCD:
-							fprintf(outfp, "  %s ", pxf->px_fname);
+							fprintf(outfp, "  `%s` ", pxf->px_fname);
 							fprintf(outfp, "%s", get_sql_type(typemap, pxf->px_ftype, pxf->px_fdc));
 							first = 1;
 							break;
@@ -2310,7 +2310,7 @@
 						strrep(pxf->px_fname, ' ', '_');
 						if(first == 1)
 							fprintf(outfp, ",");
-						fprintf(outfp, "%s", pxf->px_fname);
+						fprintf(outfp, "`%s`", pxf->px_fname);
 						first = 1;
 					}
 					pxf++;
@@ -2324,7 +2324,7 @@
 			for(i=0; i<primarykeyfields; i++) {
 				if(fieldregex == NULL ||  selectedfields[i]) {
 					strrep(pxf->px_fname, ' ', '_');
-					fprintf(outfp, "CREATE INDEX %s_%s_index on %s (%s);\n", tablename, pxf->px_fname, tablename, pxf->px_fname);
+					fprintf(outfp, "CREATE INDEX `%s_%s_index` on `%s` (`%s`);\n", tablename, pxf->px_fname, tablename, pxf->px_fname);
 				}
 				pxf++;
 			}
@@ -2340,7 +2340,7 @@
 			}
 
 			if(usecopy) {
-				fprintf(outfp, "COPY %s (", tablename);
+				fprintf(outfp, "COPY `%s` (", tablename);
 				first = 0;  // set to 1 when first field has been output
 				pxf = PX_get_fields(pxdoc);
 				/* output field name */
@@ -2366,7 +2366,7 @@
 							case pxfFmtMemoBLOb:
 							case pxfGraphic:
 							case pxfOLE:
-								fprintf(outfp, "%s", pxf->px_fname);
+								fprintf(outfp, "`%s`", pxf->px_fname);
 								first = 1;
 								break;
 						}
@@ -2594,7 +2594,7 @@
 								case pxfBLOb:
 								case pxfGraphic:
 								case pxfOLE:
-									str_buffer_print(pxdoc, sbuf, "%s", pxf->px_fname);
+									str_buffer_print(pxdoc, sbuf, "`%s`", pxf->px_fname);
 									first = 1;
 									break;
 							}
@@ -2609,9 +2609,9 @@
 						first = 0;  // set to 1 when first field has been output
 						offset = 0;
 						if(shortinsert)
-							fprintf(outfp, "insert into %s values (", tablename);
+							fprintf(outfp, "insert into `%s` values (", tablename);
 						else
-							fprintf(outfp, "insert into %s %s values (", tablename, str_buffer_get(pxdoc, sbuf));
+							fprintf(outfp, "insert into `%s` %s values (", tablename, str_buffer_get(pxdoc, sbuf));
 						pxf = PX_get_fields(pxdoc);
 						for(i=0; i<PX_get_num_fields(pxdoc); i++) {
 							if(fieldregex == NULL ||  selectedfields[i]) {
