Changeset 19109 for trunk/FACT++
- Timestamp:
- 07/31/18 20:43:31 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/fits2sql.cc
r19108 r19109 8 8 9 9 #include "zfits.h" 10 11 /*12 #include <TROOT.h>13 #include <TFile.h>14 #include <TTree.h>15 #include <TLeaf.h>16 #include <TError.h>17 */18 10 19 11 using namespace std; … … 65 57 ("sql-type", vars<Map>(), "Allows to overwrite the calculated SQL type for a given column e.g. 'sql-column-name/UNSIGNED IN'") 66 58 ("ignore", vars<string>(), "Ignore the given leaf, if the given regular expression matches") 59 ("unsigned", vars<string>(), "In fits files per default columns are signed. This interpretss the column as unsigned value. Use the FITS column name.") 67 60 ("primary", vars<string>(), "List of columns to be used as primary keys during table creation (in connection with --create)") 68 61 ("first", var<int64_t>(int64_t(0)), "First event to start with (default: 0), mainly for test purpose") 69 62 ("max", var<int64_t>(int64_t(0)), "Maximum number of events to process (0: all), mainly for test purpose") 70 ("engine", var<string>("InnoDB"), "Database engine to be used when a new table is created") 63 ("engine", var<string>(""), "Database engine to be used when a new table is created") 64 ("row-format", var<string>(""), "Defines the ROW_FORMAT keyword for table creation") 71 65 ("duplicate", var<string>(""), "Specifies an assignment_list for an 'ON DUPLICATE KEY UPDATE' expression") 72 66 ("ignore-errors", po_switch(), "Adds the IGNORE keyword to the INSERT query (turns errors into warnings, ignores rows with errors)") … … 149 143 "once. Note that the combination of these columns must be unique.\n" 150 144 "\n" 151 "All columns are created as NOT NULL as default and the table is created as"152 " InnoDB (default).\n"145 "All columns are created as NOT NULL as default. To force a database engine " 146 "and/or a storage format, use --engine and --rot-format.\n" 153 147 "\n" 154 148 "Usually, the INSERT query would fail if the PRIMARY key exists already. " … … 199 193 kDouble, 200 194 kInt8, 195 kUInt8, 201 196 kInt16, 197 kUInt16, 202 198 kInt32, 199 kUInt32, 203 200 kInt64, 201 kUInt64, 204 202 // kMJD, 205 203 }; … … 208 206 { 209 207 { 'A', { kVarchar, "VARCHAR" } }, 208 { 'a', { kVarchar, "VARCHAR" } }, 210 209 { 'L', { kBool, "BOOLEAN" } }, 210 { 'l', { kBool, "BOOLEAN" } }, 211 211 { 'B', { kInt8, "TINYINT" } }, 212 { 'b', { kUInt8, "TINYINT UNSIGNED" } }, 212 213 { 'I', { kInt16, "SMALLINT" } }, 214 { 'i', { kUInt16, "SMALLINT UNSIGNED" } }, 213 215 { 'J', { kInt32, "INT" } }, 216 { 'j', { kUInt32, "INT UNSIGNED" } }, 214 217 { 'K', { kInt64, "BIGINT" } }, 218 { 'k', { kUInt64, "BIGINT UNSIGNED" } }, 215 219 { 'E', { kFloat, "FLOAT" } }, 220 { 'e', { kFloat, "FLOAT" } }, 216 221 { 'D', { kDouble, "DOUBLE" } }, 222 { 'd', { kDouble, "DOUBLE" } }, 217 223 }; 218 224 … … 246 252 case kBool: 247 253 case kInt8: str << int32_t(reinterpret_cast<int8_t*>(ptr)[index]); break; 254 case kUInt8: str << uint32_t(reinterpret_cast<uint8_t*>(ptr)[index]); break; 248 255 case kInt16: str << reinterpret_cast<int16_t*>(ptr)[index]; break; 256 case kUInt16: str << reinterpret_cast<uint16_t*>(ptr)[index]; break; 249 257 case kInt32: str << reinterpret_cast<int32_t*>(ptr)[index]; break; 258 case kUInt32: str << reinterpret_cast<uint32_t*>(ptr)[index]; break; 250 259 case kInt64: str << reinterpret_cast<int64_t*>(ptr)[index]; break; 260 case kUInt64: str << reinterpret_cast<uint64_t*>(ptr)[index]; break; 251 261 case kNone: 252 262 break; … … 285 295 286 296 const string engine = conf.Get<string>("engine"); 297 const string row_format = conf.Get<string>("row-format"); 287 298 const string duplicate = conf.Get<string>("duplicate"); 288 299 … … 298 309 const vector<string> _ignore = conf.Vec<string>("ignore"); 299 310 const vector<string> primary = conf.Vec<string>("primary"); 311 312 const vector<string> notsigned = conf.Vec<string>("unsigned"); 300 313 301 314 // ------------------------------------------------------------------------- … … 381 394 continue; 382 395 383 const char tn = col.type; 396 const char tn = find(notsigned.cbegin(), notsigned.cend(), ic.first)!=notsigned.cend() ? 397 tolower(col.type) : toupper(col.type); 384 398 385 399 auto it = ConvFits.find(tn); … … 421 435 if (!col.unit.empty()) 422 436 query += "["+col.unit+"]"; 423 query += ": "+col.comment+"'"; 437 if (!col.comment.empty()) 438 query += ": "+col.comment; 439 query += +"'"; 440 if (N>1 && i!=N-1) 441 query += ",\n"; 424 442 } 425 443 … … 463 481 query += 464 482 ")\n" 465 "DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci\n" 466 "ENGINE="+engine+"\n" 467 "COMMENT='created by "+conf.GetName()+"'\n"; 483 "DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci\n"; 484 if (!engine.empty()) 485 query += "ENGINE="+engine+"\n"; 486 if (!row_format.empty()) 487 query += "ROW_FORMAT="+row_format+"\n"; 488 query += "COMMENT='created by "+conf.GetName()+"'\n"; 468 489 469 490 … … 530 551 else 531 552 query += " `"+c->column+"["+to_string(i)+"]`"; 553 554 if (N>1 && i!=N-1) 555 query += ",\n"; 532 556 } 533 557 } … … 564 588 if (print_insert && i==0) 565 589 query += " /* "+c->column+" -> "+c->branch+" */"; 590 591 if (N>1 && i!=N-1) 592 query += ",\n"; 566 593 } 567 594 }
Note:
See TracChangeset
for help on using the changeset viewer.