26 #ifndef __ROWSETTOSQL_H_INCL__
27 #define __ROWSETTOSQL_H_INCL__
94 template<
typename _Reader>
97 const size_t cc = reader.columnCount();
102 typename _Reader::iterator cur, end;
103 cur = reader.begin();
105 for(; cur != end; ++cur)
106 for(
size_t col = 0; col < cc; ++col )
107 into[col].Process( cur.GetType( col ) );
118 template<
typename _Reader>
119 bool ReaderToSQL(
const char* table_name,
const char* key_field, FILE* out, _Reader& reader )
121 const size_t cc = reader.columnCount();
123 const size_t key_col = reader.FindColumn( key_field );
126 sLog.Error(
"ReaderToSQL",
"Unable to find key column '%s'.", key_field );
130 std::vector<ReaderColumnContentDesc> types;
131 ClassifyColumnTypes<_Reader>( types, reader );
134 "--- %s schema ---\n"
136 "CREATE TABLE `%s` (\n",
141 std::string field_list;
142 for(
size_t col = 0; col < cc; ++col )
144 const char* colName = reader.columnName( col );
149 ( 0 != col ?
",\n" :
"" ),
153 ( key_col == col ?
" PRIMARY KEY" :
"" )
159 field_list += colName;
167 "--- end %s schema ---\n"
171 ( NULL == key_field ?
",\n PRIMARY KEY()" :
"" ),
176 typename _Reader::iterator cur, end;
177 cur = reader.begin();
179 for(
size_t rowIndex = 0; cur != end; ++cur, ++rowIndex )
184 fprintf( out,
";\n" );
186 fprintf( out,
"INSERT INTO `%s`(%s) VALUES ", table_name, field_list.c_str() );
192 for(
size_t col = 0; col < cc; ++col )
197 fprintf( out,
"%s", cur.GetAsString( col ).c_str() );
205 "--- end %s data ---\n",
static const char *const smTypeStrings[]
Helper class for column description.
static const char *const smNullStrings[]
ReaderColumnContentDesc()
const char * typeString() const
bool ReaderToSQL(const char *table_name, const char *key_field, FILE *out, _Reader &reader)
Dumps rowset to SQL.
void Process(const PyRep::PyType t)
Processes PyRep type to determine type of column.
#define sLog
Evaluates to a NewLog instance.
const char * nullString() const
PyType
Python wire object types.
void ClassifyColumnTypes(std::vector< ReaderColumnContentDesc > &into, _Reader &reader)
Classifies columns using ReaderColumnContentDesc.
const size_t INSERT_QUERY_ROW_LIMIT