What is the D7 equivalent of CCK "content_instance_tablename" in db_query? I am porting a D6 module to D7 which deals with controlling field access of CCK fields. I can now successfully enable my port without any errors but receive a fatal error when trying to create new content.

The issue is the the "content_table_instance" in db_query which as far as I understand no longer exists in D7 due to the CCK --> Fields move. I am having a lot of trouble finding exactly what the alternative of "content_table_instance" is in D7. Any suggestions?

Here is the section of the code:

$result = db_query("SELECT nfi.field_name, nfi.label
  FROM {" . content_instance_tablename() . "} nfi
    INNER JOIN {" . content_field_tablename() . "} nf ON nfi.field_name = nf.field_name
  WHERE nfi.type_name = '%s' AND nf.active = 1 AND nf.locked = 0", $type_name);
Both functions in your code (content_field_tablename() and content_instance_tablename()) just return a string based on the version number of the CCK module.

The Drupal 7 equivalents would be the field_config and field_config_instance tables respectively, as defined in field_schema.

Remember fields can be attached to any entity in Drupal 7 (not just nodes) so you'll need to change your code accordingly.

If you're using this query to get information about the field metadata you might want to use one of the Field Info API functions instead, e.g.

$all_field_instance_data = field_info_instances();


or

$single_field_instance_data = field_info_instance('node', 'field_some_field', 'article');