I have a few custom tables in my Drupal database that were created manually.
Is there some Drupal module to allow viewing and editing records in custom tables?
Tables are simple, no joins used.
Or it's best to build some grid/record interfaces manually in custom module?
For reporting, the recommended way is likely to use Views integration. If your tables have primary keys, it's a simple matter of defining them to Views by implementing:
hook_views_api() to declare Views integration
hook_views_data() to declare the tables and their fields, assuming they use only simple data types
You can take the integration examples in views/modules/node.views.inc and views/modules/node/*. Module TableWizard can help you with this.
This still won't provide you with editability, though. For this, you could either build the module on your own using Form API, or import the content of these tables as nodes, and use drupal builtin editing on the nodes, assuming you do not mind the data being in node format after that.
You might consider using both Views and the new Data module:
The Data module provides
* an API for dynamically allocating tables for single-row records.
* an API for insert/update/delete operations and describing how tables join to each other.
* automatic views integration.
* a way to export table definitions to code.
The included Data UI module provides
* UI to add new database tables.
* UI to add or alter columns to existing tables managed by Data module.
* UI to define joins between tables.
* UI to solve conflicts between table in database and schema information.
* default views for tables managed by Data module.
* UI to add existing tables that are unclaimed by other modules to Data's table management.
keep an eye on this https://drupal.org/project/dba
they'll be coming up with these functionalities
ability to execute sql scripts and see the resulting output (ie, create/alter/update tables)
overview table listing including total row counts for each
ability to drop one or more tables at a time
ability to edit a specific row (using simple form)
ability to delete a specific row
in MySQL, ability to check and repair one or more tables at a time
Related
I am new to MySQL databases and I'm trying to create a web stock and production database, using PHP.
In this inventory software, I am trying to create a table in which products are created and also their components inserted. But if a product has a different number of components, I wanted to know if there is any way to add more components columns from the management page of the website.
Another thing is that these components are taken from another table, and as long as a new product order is created, the quantity of those used components should be subtracted from the components table. (but this is a major issue, solving the first issue should be enough for now).
Yes, you can add, or remove, columns from a database table at any time.
However, I would not do this. You have to try and design a database that can handle products with a varying number of component. Normally this would be done this way:
Create a table for your products.
Create a table for your components.
Create a linking table product_components, to indicate what components a product consists off.
See: Using linking tables for many to many relationships in MySQL
You need to know about relationships in mysql. There are basically 3 types(some may say 4 though) of relationships available in a relational database like mysql.
Here according to your description you can use
1 to many
many to many
relationship in your database. This may help you-
https://afteracademy.com/blog/what-are-the-different-types-of-relationships-in-dbms
[Situation]
I must her-build a existing application where you can choose from a list of clients and generate csv lists.
The problem is that all the client have separate custom long Oracle:SQL queries with sub queries to build a dataset and then make a export file csv.
So.. normally I would work with LV:Models where it interacts with DB-Views or tables in Oracle.
This is now not possible because there are to many custom joins etc
and shared tables in the querys.
So.. to rebuild one by one in LV, I must have for the DB interaction a (DB)class where I can put the existing SQL (maybe adjust a little) and Use it in the Controllers/Some Models...
Q: How must I set up the architect patron for the custom sql queries
classses.
In Models? but there is no direct db:view/table
Custom Class and use some LV:DB classes?
Who can point me in the right direction?
p.n. there are about 20 custom old classes with large sql queries..
Regards.
M
I am developing a plugin in WordPress that is about to store configurable entities. They are jobs to be done by Cron. There are plenty of them and each one has name, frequency and some additional data.
There are discussions how to store post-related data in plugins, whether to use postmeta table or own tables. It is officially adviced to use postmeta whenever possible. But what if those entities are not posts? I have 3 possibilities:
Use separate table(s) to store them
Use options table
Make those entities posts with custom post type
I used to keep this kind of information in options table, but how would you do that?
Basically, when you are trying to decide if you need a custom table or not, answer a simple question: does my data need indexes and fast searching? If yes - go with custom tables. If not - e.g.:
this data is being read from database with the post itself - use postmeta
this data is used rarely and is called directly by keys - use options
Else, if you need to store a lot of structured data, perform selects, sorts, or even joins etc - custom db table is your option. Read the docs and do it using core functions and features, like db_delta() function etc. There's nothing wrong in using custom db tables. Just do it right, the "WordPress way".
I have an entity which uses a table called software. In the UI of the app I'm developing, all of the entries in software are useful to users in lists or dropdowns in forms. Unfortunately, the database automatically inherits another table called software_dynamic when selecting from software.
This makes it so the UI has approximately 15,000 software entries it doesn't need when using the entity in the Symfony FormBuilder, for example. Another example would be something like this:
$doctrine->getManager->getRepository('Software')->findAll();
Returns all of the extraneous entries the users don't want to see as well.
What I need to do is get Doctrine to run a query like select * from only software. I've attempted to do this through the query_builder option in the FormBuilder, but I could only find a way to return an array of the results I wanted - Not an instance of QueryBuilder like the FormBuilder requires.
My concern is that my only option here is to manually query for the software, then pass that into the form as an option. This isn't ideal, but it's starting to seem like the only option.. I'm just hoping someone out there knows how to tell a Doctrine entity not to inherit from other tables, essentially using the only statement in SQL.
I have no way to discriminate between software and software_dynamic through Doctrine; they're identical tables but one is manually populated from a CRUD (The ones the users want to see) and the other is populated automatically through an API (Only useful to the backend).
Have you accidentally set the fetch mode to EAGER loading? This would indeed cause the opposite effect of what you desire.
However, when you do require eager loading in some cases:
$query = $em->createQuery("SELECT e FROM MyProject\Entity e");
$query->setFetchMode("MyProject\AssociatedEntity", "field", "EAGER");
$query->execute();
When running SELECT queries it seems as if Yii is often performing each one twice. The first is a COUNT() and the second is the actual query.
What is causing this? It seems terribly inefficient.
In a related note, why does Yii perform a SHOW COLUMNS FROM and SHOW CREATE TABLE so often? Doesn't setting up a relation within the Model tell Yii enough about the schema?
I assume you are using active records a lot in conjunction with listing widgets such as CGridView and CListView.
What is causing this? It seems terribly inefficient.
Well, in order for the pagination to work in CListView and CGridView, the assigned CActiveDataProvider (or actually any data provider) needs to fetch the total item count. This won't work with the result set which usually has a LIMIT clause applied. Hence, an additional COUNT() is performed to retrieve said number.
In a related note, why does Yii perform a SHOW COLUMNS FROM and SHOW CREATE TABLE so often? Doesn't setting up a relation within the Model tell Yii enough about the schema?
No. Yii does far more than managing related models. Part of the AR abstraction layer is also to determine which fields are available in a table and hence can be accessed on a model representing a table row. However, you don't have to live with this as schemata can be cached conveniently. To do so, follow these steps:
Configure a caching component such as CApcCache in your protected/config/main.php in the components stanza.
Change the configuration of your db component so it contains the following lines:
'schemaCacheId'=>'cache', // This is the name of the cache component you
// configured in step 1. It's also the default value.
'schemaCacheDuration'=>3600, // Cache table schemata for an hour.
// Set this higher if you like.
A word of advice; don't do this in your development environment: If your database design changes, AR models might not reflect this due to stale caches.