Changeset 38998
- Timestamp:
- Oct 29, 2015, 10:49:32 AM (11 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/tools/src/fits_to_mysql.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/tools/src/fits_to_mysql.c
r38997 r38998 34 34 TYPE_INT64, 35 35 TYPE_FLOAT, 36 TYPE_DOUBLE 36 TYPE_DOUBLE, 37 TYPE_SEQUENCE, 37 38 } TypeInt; 38 39 … … 53 54 char *TABLENAME; 54 55 char *TABLEPREFIX; 56 char *TABLESUFFIX; 57 char *SEQUENCE_COLUMN; 58 int SEQUENCE_COLUMN_START; 55 59 56 60 int args (int *argc, char **argv); … … 60 64 ColumnDef *parse_table (Header *header, int *ncolumn); 61 65 int create_table (ColumnDef *columns, int Ncolumns, char *extname, IOBuffer *insert, MYSQL *mysql); 62 void write_data (ColumnDef *columns, int Ncolumns, FTable *table, IOBuffer *insert, MYSQL *mysql);66 void write_data (ColumnDef *columns, int Ncolumns, int start, FTable *table, IOBuffer *insert, MYSQL *mysql); 63 67 64 68 void *gfits_get_bintable_column_data_by_Ncol (FTable *table, int Nfield, char *type, off_t *Nrow, int *Ncol, char nativeOrder); … … 167 171 fprintf (stderr, "read "OFF_T_FMT" rows\n", header.Naxis[1]); 168 172 169 write_data (columns, Ncolumns, &table, &insert, mysqlReal);173 write_data (columns, Ncolumns, start, &table, &insert, mysqlReal); 170 174 171 175 start += Nrows; … … 195 199 FREE (TABLENAME); 196 200 FREE (TABLEPREFIX); 201 FREE (TABLESUFFIX); 202 FREE (SEQUENCE_COLUMN); 197 203 198 204 ohana_memdump (TRUE); … … 228 234 int Nfields; 229 235 if (!gfits_scan (header, "TFIELDS", "%d", 1, &Nfields)) return NULL; 236 237 // generate the sequence column first so that any actual table columns which match the 238 // requested name get a uniquified colname 239 if (SEQUENCE_COLUMN) { 240 column[Ncolumn].colname = strcreate (SEQUENCE_COLUMN); 241 column[Ncolumn].rawname = strcreate (SEQUENCE_COLUMN); 242 column[Ncolumn].format = NULL; 243 replace_dot_with_underscore (column[Ncolumn].colname); 244 column[Ncolumn].Nval = 0; 245 column[Ncolumn].Nbytes = 0; 246 column[Ncolumn].type = TYPE_SEQUENCE; 247 Ncolumn++; 248 } 230 249 231 250 // first, extract the table data: … … 311 330 312 331 char *tablename = NULL; 313 if (TABLEPREFIX) { 314 if (TABLENAME) { 315 strextend (&tablename, "%s%s", TABLEPREFIX, TABLENAME); 316 } else { 317 strextend (&tablename, "%s%s", TABLEPREFIX, extname); 318 } 332 int length = TABLENAME ? strlen(TABLENAME) : strlen(extname); 333 if (TABLEPREFIX) length += strlen(TABLEPREFIX); 334 if (TABLESUFFIX) length += strlen(TABLESUFFIX); 335 ALLOCATE_ZERO (tablename, char, length + 1); 336 if (TABLEPREFIX) strcpy (tablename, TABLEPREFIX); 337 if (TABLENAME) { 338 strcat (tablename, TABLENAME); 319 339 } else { 320 tablename = TABLENAME ? strcreate (TABLENAME) : strcreate (extname); 321 } 340 strcat (tablename, extname); 341 } 342 if (TABLESUFFIX) strcat (tablename, TABLESUFFIX); 322 343 replace_dot_with_underscore (tablename); 323 344 … … 374 395 PrintIOBuffer (&buffer, "%s VARCHAR(%d)", columns[i].colname, columns[i].Nval); 375 396 break; 397 case TYPE_SEQUENCE: 398 // SEQUENCE is a (single) special column with a sequence of values from SEQUENCE_COLUMN_START 399 PrintIOBuffer (&buffer, "%s INT", columns[i].colname); 400 break; 376 401 default: 377 402 myAbort ("oops"); … … 415 440 } 416 441 417 void write_data (ColumnDef *columns, int Ncolumns, FTable *table, IOBuffer *insert, MYSQL *mysql) {442 void write_data (ColumnDef *columns, int Ncolumns, int start, FTable *table, IOBuffer *insert, MYSQL *mysql) { 418 443 419 444 int i, j, Nf; … … 429 454 430 455 // first, extract the table data: (probably should save this structure and re-use in create_table) 456 int Nfield = 1; 431 457 for (i = 0; i < Ncolumns; i++) { 432 458 off_t Nrow; 433 459 int Ncol; 434 460 char type[16]; 435 data[i] = gfits_get_bintable_column_data_by_Ncol (table, i + 1, type, &Nrow, &Ncol, FALSE); 436 myAssert (Nrow == Ny, "oops"); 461 462 // we need to skip past virtual columns that do not correspond to actual table columns 463 if (columns[i].type == TYPE_SEQUENCE) { data[i] = NULL; continue; } 464 data[i] = gfits_get_bintable_column_data_by_Ncol (table, Nfield, type, &Nrow, &Ncol, FALSE); 465 Nfield ++; 466 myAssert (Ncol == columns[i].Nval, "oops (1)"); 467 myAssert (Nrow == Ny, "oops (2)"); 437 468 } 438 469 … … 444 475 for (Nf = 0; Nf < Ncolumns; Nf++) { 445 476 switch (columns[Nf].type) { 477 case TYPE_SEQUENCE: 478 // XXX need to include offset from table block and possible starting offset 479 PrintIOBuffer (&output, "%d", i + start + SEQUENCE_COLUMN_START); 480 break; 446 481 case TYPE_CHAR: { 447 482 char line[1024]; … … 719 754 remove_argument (N, argc, argv); 720 755 } 756 TABLESUFFIX = NULL; 757 if ((N = get_argument (*argc, argv, "-tablesuffix"))) { 758 remove_argument (N, argc, argv); 759 TABLESUFFIX = strcreate (argv[N]); 760 remove_argument (N, argc, argv); 761 } 762 763 SEQUENCE_COLUMN = NULL; 764 if ((N = get_argument (*argc, argv, "-sequence-column"))) { 765 remove_argument (N, argc, argv); 766 SEQUENCE_COLUMN = strcreate (argv[N]); 767 remove_argument (N, argc, argv); 768 } 769 SEQUENCE_COLUMN_START = 0; 770 if ((N = get_argument (*argc, argv, "-sequence-column-start"))) { 771 remove_argument (N, argc, argv); 772 SEQUENCE_COLUMN_START = atoi (argv[N]); 773 remove_argument (N, argc, argv); 774 } 721 775 722 776 return TRUE;
Note:
See TracChangeset
for help on using the changeset viewer.
