I need list of the database tables used by Moodle.
How can I get it ? Is there any API for that either in Java or PHP ?
I checked - APIs like - Data definition API, Data Manipulation API , Web Services but I could not find what I require.
These API help getting data from Moodle, but I need MetaData.
Please help. Thanks in Advance.
You can use this in Moodle
$tables = $DB->get_tables();
also
foreach ($tables as $table) {
$columns = $DB->get_columns();
foreach ($columns as $column) {
...
}
}
Or use the information_schema
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'yourmoodledatabasename'
Related
I'm developing a Springboot Application. One of the features of this application is to show Database Information (like tablename, no.of records, etc) on the UI. Currently I'm stuck in writing the implementation for the method public int getRowCountByTableName(String tablename).
There are lot of tables in the database, based on the given name I have to return the rowcount of that table. I have done some research on this and found that Hibernate Criteria API can help.
String cName = map.get(tableName);//There is map which has <tableName,CanonicalNameOfTheEntity>
className = Class.forName(cName);
Criteria cr = dbSession.createCriteria(className);
cr.setProjection(Projections.rowCount());
rowCount = (Long) cr.uniqueResult();
But the problem is that Hibernate Criteria API is deprecated. So I'm not supposed to use this deprecated api as per my organization policy.
Can someone help me finding an alternative way to do this?
Thanks in advance!!
I'm trying to emulate the query Select * from namespace.set where pk="something" through aeropsike's java client. I know that we can query on a secondary index through "Filter", and create "PredExp" for other predicates, but I'm unable to figure out how we can query on a primary key.
Any help would be appreciated. Thanks a lot in advance.
Edit : I have multiple bins in my set, if that makes any difference.
I figured it out. You just have to create a "new key" while querying through the java aerospike client.
Record record = aerospikeClient.get(null, new Key(namespace, cacheName, key), binNames)
Refer to the discussion: https://discuss.aerospike.com/t/primary-key-search/558/6
I created python script that sends notifications when result declared but I want to make website that takes data of student email id and store in database.
Now here problem is that I don't know django framework so it takes time to make website.
Java, database connection, Data insertion,
Servelet calling easily do that by me.
Want to know way that java html css takes input from user and stores in database and then python program retrieves that data.
Hope you understand my question.
If you know python, I think Django might be a good choice for you. Django itself attempts to support as many features as possible on the backend. You only need to configure the database parameters in settings.py and Django ORM can automate the transfer of data stored in tables into objects. You don't have to implement the features yourself and it saves you tons of time.
Django has its own ModelForm class. It maps to the Models(eg. Student), it is quite easy to submit your Student info and store it in db.
# settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': '/path/to/my.cnf',
},
}
}
# my.cnf
[client]
database = NAME
user = USER
password = PASSWORD
default-character-set = utf8
If you insist using Java to implement the database backend, for sure you can share it with python. Some choices like JDBC, Hibernate and Mybatis.
Yes you can share the DB, you'll have to install the corresponding dependencies for connecting python to the DB as well as for Java. I've done this with postgresql, mysql and mssql
I want to display the data of a postgresql database using the CRUD in the play framework; I looked for any examples to get idea which I didn't find after a long time of searching in google. Someone help me with this if you can or post a valid link regarding this. Thanks in advance!
I use, Play 1.2.5, java and postgresql.
I assume you want to do this in your application code in runtime.
You can execute query using DB plugin to search DB metadata using native PostgreSQL queries.
Here's an example how to get column names of my system DOCUMENT table:
List<String> columns = new ArrayList<>();
ResultSet result = DB.executeQuery("select column_name from INFORMATION_SCHEMA.COLUMNS where table_name = 'DOCUMENT';");
while(result.next()) {
String column = result.getString(1);
columns.add(column);
}
This note that code is somewhat simplified and you should use prepared statements if anything in this query will be inserted from data that user or any other system entered.
Use DB.getConnection().prepareStatement() to get PreparedStatement instance.
I am working in a Spring web application using Cassandra with Astyanax client. I want to transform result data retrieved from Cassandra queries to a POJO, but I do not know which library or Astyanax API support this.
For example, I have User column family (CF) with some basic properties (username, password, email) and other related additional information can be added to this CF. Then I fetch one User row from that CF by using OperationResult> to hold the data returned, like this:
OperationResult<ColumnList<String>> columns = getKeyspace().prepareQuery(getColumnFamily()).getRow(rowKey).execute();
What I want to do next is populating "columns" to my User object. Here, I have 2 problems and could you please help me solve this:
1/ What is the best structure of User class to hold the corresponding data retrieved from User CF? My suggestion is:
public class User {
String userName, password, email; // Basic properties
Map<String, Object> additionalInfo;
}
2/ How can I transform the Cassandra data to this POJO by using a generic method (so that it can be applied to every single CF which has mapped POJO)?
I am so sorry if there are some stupid dummy things in my questions, because I have just approached NoSQL concepts and Cassandra as well as Astyanax for 2 weeks.
Thank you so much for your help.
You can try Achilles : https://github.com/doanduyhai/achilles, an JPA compliant Entity Manager for Cassandra
Right now there is a complete implementation using Thrift API via Hector.
The CQL3 implementation using Datastax Java Driver is in progress. A beta version will be available in few months (July-August 2013)
CQL3 is great but it's still too low level because you need to extract the data yourself from the ResultSet. It's like coming back to the time when only JDBC Template was available.
Achilles is there to fill the gap.
I would suggest you to use some library like Playorm using which you can easily perform CRUD operations on your entities. See this for an example that how you can create a User object and then you can get the POJO easily by
User user1 = mgr.find(User.class, email);
Assuming that email is your NoSqlId(Primary key or row key in Cassandra).
I use com.netflix.astyanax.mapping.Mapping and com.netflix.astyanax.mapping.MappingCache for exactly this purpose.