File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -67,6 +67,15 @@ class pg_result_t
6767 return std::string (get_value (row, col), get_length (row, col));
6868 }
6969
70+ /* *
71+ * Get the column number from the name. Returns -1 if there is no column
72+ * of that name.
73+ */
74+ int get_column_number (std::string const & name) const noexcept
75+ {
76+ return PQfnumber (m_result.get (), (' "' + name + ' "' ).c_str ());
77+ }
78+
7079private:
7180 struct pg_result_deleter_t
7281 {
Original file line number Diff line number Diff line change @@ -119,10 +119,10 @@ void table_t::start(std::string const &conninfo,
119119 } // appending
120120 else {
121121 // check the columns against those in the existing table
122- auto res = m_sql_conn->query (
122+ auto const res = m_sql_conn->query (
123123 PGRES_TUPLES_OK , " SELECT * FROM {} LIMIT 0" _format (m_target->name ));
124124 for (auto const &column : columns) {
125- if (PQfnumber ( res.get (), ( ' " ' + column.name + ' " ' ). c_str () ) < 0 ) {
125+ if (res.get_column_number ( column.name ) < 0 ) {
126126 fmt::print (stderr, " Adding new column \" {}\" to \" {}\"\n " ,
127127 column.name , m_target->name );
128128 m_sql_conn->exec (" ALTER TABLE {} ADD COLUMN \" {}\" {}" _format (
You can’t perform that action at this time.
0 commit comments