Qsql - How to access table column information ?
- 
Hello, I am trying to access the information of a table columns such as name, type, if it is a primary or foreign key... I tried to use QsqlRecord but I cannot get all the information, notably about the primary key. I only have: row=selected_index.row() column=selected_index.column() local_record=self.model_columns.record(row) for n in range(0,len(local_record)): print("name: "+str(local_record.field(n).name())) print("required status: "+str(local_record.field(n).requiredStatus())) print("length: "+str(local_record.field(n).length())) print("type: "+str(QVariant.typeToName(local_record.field(n).type()))) print("--------")Is there a better solution to get a result looking like, for example: my column: name, integer, primary/foreign key, not null ? 
- 
@JonB Thank you for this information, I will look into the SQLite documentation. And sorry for deleting/moving my old post. 
- 
Hello, I am trying to access the information of a table columns such as name, type, if it is a primary or foreign key... I tried to use QsqlRecord but I cannot get all the information, notably about the primary key. I only have: row=selected_index.row() column=selected_index.column() local_record=self.model_columns.record(row) for n in range(0,len(local_record)): print("name: "+str(local_record.field(n).name())) print("required status: "+str(local_record.field(n).requiredStatus())) print("length: "+str(local_record.field(n).length())) print("type: "+str(QVariant.typeToName(local_record.field(n).type()))) print("--------")Is there a better solution to get a result looking like, for example: my column: name, integer, primary/foreign key, not null ? @Jule 
 [I JUST TYPED THE FOLLOWING INTO YOUR QUESTION BUT WHEN I WENT TO SUBMIT I FOUND YOU HAD DELETED YOUR (OLD) TOPIC. PLEASE TRY NOT TO DO THAT! Here it is again.]The format of the information is obviously not important --- you can control that once you have the information. I don't think Qt SQL code gives you any way to access "meta information" like you want. For example, I don't think it ever looks to see/cares whether a column is in a foreign key. The information would not be supplied/obtained in a "standard" way across SQLs (SQLite, MYSQL, MSSQL, ...). But I think you will find each of these offers some way to issue a SQL statement which returns such "meta" information. For example, it may have some system tables with special names on which you can perform a SELECT ... WHERE ...and the columns returned tell you about the tables/columns meta information in the database. You would discover that by consulting the documentation for whichever flavor of SQL you are using.
- 
@Jule 
 [I JUST TYPED THE FOLLOWING INTO YOUR QUESTION BUT WHEN I WENT TO SUBMIT I FOUND YOU HAD DELETED YOUR (OLD) TOPIC. PLEASE TRY NOT TO DO THAT! Here it is again.]The format of the information is obviously not important --- you can control that once you have the information. I don't think Qt SQL code gives you any way to access "meta information" like you want. For example, I don't think it ever looks to see/cares whether a column is in a foreign key. The information would not be supplied/obtained in a "standard" way across SQLs (SQLite, MYSQL, MSSQL, ...). But I think you will find each of these offers some way to issue a SQL statement which returns such "meta" information. For example, it may have some system tables with special names on which you can perform a SELECT ... WHERE ...and the columns returned tell you about the tables/columns meta information in the database. You would discover that by consulting the documentation for whichever flavor of SQL you are using.
- 
@JonB Thank you for this information, I will look into the SQLite documentation. And sorry for deleting/moving my old post. 
- 
@Jule 
 I think for SQLite How to read metadata from Sqlite databaseSELECT * FROM sqlite_master WHERE tbl_name = 't1';
- 
J Jule has marked this topic as solved on
 
