def _get_table_name(self, table_elt): """ Get the database-compatible name of a table. @param IN table_elt Table XML element @return The name as a string """ return get_db_table_name(table_elt)
def table_elt_to_pkey_text(table_elt): """ Translate a table XML element into a pkey text for Xylinq. @param IN table_elt Table XML element @return Pkey text """ # Get the necessary data table_info = _TableInfo() # - Table name table_info.table_name = get_db_table_name(table_elt) # - Columns columns_elt = table_elt.find("columns") if not columns_elt: raise Exception("No columns section for table %s" % table_info.table_name) column_elt_list = [c for c in columns_elt.findall("column")] if not column_elt_list: raise Exception("No columns for table %s" % table_info.table_name) table_info.all_xy_col_names = [get_xy_column_name(c) for c in column_elt_list] table_info.all_db_col_names = [get_db_column_name(c) for c in column_elt_list] table_info.all_db_col_name_max_size = max([len(db_col_name) for db_col_name in table_info.all_db_col_names]) # - Primary key columns primary_key_elt = table_elt.find("primary_key") if not primary_key_elt: raise Exception("No primary key defined for table %s" % table_info.table_name) column_elt_list = [c for c in primary_key_elt.findall("column")] if not column_elt_list: raise Exception("No columns for the primary key of table %s" % table_info.table_name) table_info.pk_db_col_names = [get_db_column_name(c) for c in column_elt_list] table_info.pk_db_col_name_max_size = max([len(db_col_name) for db_col_name in table_info.pk_db_col_names]) # Build the pkey file text result_lines = [] # - File header text = """Xylinq pkey file for %s.""" % table_info.table_name file_header = "/*\n%s\n */" % ("\n".join([" * %s" % l.strip() for l in text.splitlines()])) result_lines.append(file_header) # - Start text = """ auxcfg(map( // Use prepared stmt so that we can use '?' notation for column values // instead of having to define all the formatting. // NOTE: MAKE SURE WE KEEP TO THE SAME ORDER AS DEFINED IN THE TYPEDEF AND KEY FIELDS. "prepared", true,""" result_lines.append(text) # - select-stmt text = _build_select_stmt_section(table_info) result_lines.append("%s," % text) # - read-sql text = _build_read_sql_section(table_info) result_lines.append("%s," % text) # - write-sql text = _build_write_sql_section(table_info) result_lines.append("%s," % text) # - delete-sql text = _build_delete_sql_section(table_info) result_lines.append(text) # - End text = """))""" result_lines.append(text) result_text = "\n".join(result_lines) return result_text