Read a table from Kentico database which was not declared as 'custom table' - kentico

My question is pretty simple. I am working on Kentico 9 with its SQL Server database which contains several tables which had been added directly from the SQL Management Studio by an external contractor. The fact is that those tables are being used to store custom content which will be displayed for a site, but, in the code they don't have the code for making queries. I mean, they don't have Info and Provider classes.
https://docs.kentico.com/display/K82/Retrieving+database+data+using+ObjectQuery+API
According with this, all tables into the Kentico database can be accessed by invoking methods on these classes, but I don't have it this time.
Something like this, it will not work if I use my table name:
var user = UserInfoProvider.GetUserInfo("administrator");
var items = CustomTableItemProvider.GetItems("MyTable")
.TopN(10)
.WhereEquals("ItemCreatedBy", user.UserID)
.OrderBy("ItemCreatedWhen");
My question is:
can I query any table by its name?
One last thing:
I cannot declared those table as "custom table" because it seems to be a bug in the CMS.

Or you can pull data using your own SQL query:
var ds = ConnectionHelper.ExecuteQuery("select ....", null, QueryTypeEnum.SQLQuery);
Nevertheless I would recommend to create a custom class inside a custom module (much more robust than custom tables) instead and use the generated Info and InfoProvider classes to get and manipulate data.

I think an object has to be registered within the system (created through Kentico UI or API) in order to be pulled from DB with object query.
So I'd choose one of the following options:
Use Entity Framework or something similar to work with that data
Create appropriate custom tables or even custom module and push data there. Not sure why you can't create a custom table... What is an error you're getting?
If you need to present data on the UI only (without processing on the back end) - use just custom queries
Hope this helps.

If you are accessing in code then you could do it the good old fashioned way. If you want to pull data from the database to display on the website you could also do so by creating a custom query and using a transformation to display the fields, then use a repeater on the page to display the transformed data. Alternatively you can use a SQL datasource with a basic repeater, but you still have to create a transformation to display the data. Both methods allow you to access the data in the tables from within the CMS UI, no need to touch any code behind.

If your objective is to read data from these database tables to transform on webpage e.g. using CMS Repeater webpart, you can simply create custom query(s) in Kentico itself and load data using it. You can find the detail here on how to create custom custom queries and load data using it.
On the other hand you can also write your custom classes and define the custom methods where you can pull data using your own SQL query like this:
var ds = ConnectionHelper.ExecuteQuery("select ....", null, QueryTypeEnum.SQLQuery);
Lastly I don't think there should be any issue to create custom table instead of those direct DB tables, only thing we have to ensure code name of custom table should be unique means don't try to use exact same name because it'll cause exception due to same table name already exist in DB. You can please share exception you getting while creating custom table so that I can help you out further.

Related

OBJECT_DEFINITION for VIEW in Azure Databricks

As the Title says, is it able to query object definition of the view in Databricks using SQL, especially for Azure Databricks?
like when using SQL Server, I'm able to query the view definition using function OBJECT_DEFINITION or Stored Procedure sp_helptext to display the SELECT statement within Views.
I'm looking all over the internet, don't find one that explains about this. May be there isn't an option?
thanks.
It's maybe not very obvious, but you can use SHOW CREATE TABLE SQL command for that - it works for both tables & views. For example if I have view as following:
create view if not exists tacls.tbl1_view as
select * except(grp) from tacls.tbl1;
then I can get definition with
show create table tacls.tbl1_view
the definition will be in the createtab_stmt column:

Are there any methods to modifying properties of all tables at a time for google docs?

I have written a article in my google docs.
I have included small tables, big tables and huge tables in different places in the files.
Now I need to modify some properties of all tables at a time.
But that seems not possible?
Are there any methods to modifying properties of all tables at a time for google docs?
PS. more details to illustrate my issue:
1. Here is a doc file with one table.
2. Right click on the table and choose Table properties
3. Now here comes more tables in a doc file
How can I deal with all the tables together? (All modifications are the same)
Method 1
When creating the tables, you can simply set all the properties on the first one and then for the next ones you can copy and paste the first one since the format will be kept.
Method 2
If you want to modify more tables at the same time, you can make use of Apps Script.
Apps Script is a powerful development platform which can be used to build web apps and automate tasks. What makes it special is the fact that it is easy to use and to create applications that integrate with G Suite.
Therefore, your task can be achieved by using this script.
Snippet
function setTableProperties() {
var doc = DocumentApp.openById("DOCUMENT_ID");
var tables = doc.getBody().getTables();
tables.forEach((table) => {
//Any instruction run with the variable table will be executed for all tables.
});
}
Explanation
The above script gathers all the tables from the wanted document and then using a for loop accesses each table from the document.
In order to set the properties of the tables as wanted, you just have to use the appropriate method/s.
The getAttributes method can be used as well in order to see exactly which properties does a table posses.
Reference
Apps Script Document Service;
Apps Script Enum Attribute;
Apps Script Table Class;
Apps Script DocumentApp Class.

Dynamic Data List: Configuring custom datasource for Select Data Definition

It is possible to specify or configure a custom datasource to load the select-options for a particular Data definition for Dynamic Data list?
The following image might clarify what I need to do:
Will it be possible that when the Dynamic Data form is shown to the User the values come from any of the liferay tables like User_, Group_ etc or from any custom plugin portlet's DB table etc.
Thanks
P.S.: Also posted on liferay forum: https://www.liferay.com/community/forums/-/message_boards/message/50483965

Custom Metadatafield in Document and Web content in Liferay

I want a metadata field getting values from database record. This metadata field should be added to document.
Can anyone provide a solution to my requirement.??
I presume you are using Liferay 6.1.
Web Content Structures
As for Web Content, you could programmatically create a JournalStructure (see JournalStuctureLocalServiceUtil) and populate the list of possible values for your structure field with values coming out of the database. You can put this "import code" inside a batch job, so your structure field and the values inside the external database are always in sync.
Document Metadata
How to do this with Metadata Sets is probably more interesting, as not only Dynamic Data Lists and Documents & Media use this in Liferay 6.1; as of 6.2, Web Content structures will utilize the same metadata API in favor of the old Journal API.
For this to implement, check out the xsd column of the DDMStructure table. It has more or less the same format as the XML for a JournalStructure, however there are more options available. Use DDMStructureLocalServiceUtil#addStructure to add such a new structure. Again, run this inside a batch so you always have the latest external DB values.

bind subsonic object collection to Microsoft report (rdlc)

Has anyone been able to use a SubSonic generated collection as a "business object datasource" with Microsoft report (rdlc)? I have generated the SubSonic class code but for some reason the report datasource window is not seeing the class as a potential object collection datasource.
Is there something I need to do for this to work?
Thanks in advance...vsdotnetguy
I have loaded Reporting Service reports from business objects before (loaded via NHibernate -- which isn't exact but close enough for argument sake).
Couple of key points:
1. return your objects in List, even if you are only returning one object.
2. You want FLAT business objects. You might have to go thru a DTO transformation to get that. By flat, I mean the most complex property you can have in a business object is a string and a number (int, decimal, double). If you are expecting to grab a value like this:
myObject.Customer.Name, forget it. Create a CustomerName property.
3. If you need data from multiple places try to break up your reports into subreports. You key off of the datasource key to figure out what data to return to the report.
I'll add more as I remember, it has been a few months since I've done this.
Yes I've done it, you should only need to make sure the project containing your reports references your SubSonic project (obviously :).
Sometimes I've also found that Visual Studio can get a little borked and require a restart before repopulating the datasource window with SubSonic generated objects.
Thx Chris and Adam,
Here is the answer I found.
In my case I wanted to dynamically set the main and subreport datasources at run time using the SubSonic object collections. However, I also wanted to design the report layout using drag and drop of the datasource columns.
But I was unable to design the report using drag&drop because none of my SubSonic collections were showing up in the Website Data Sources.
However, later while I was doing some control binding using the ObjectDataSource control, I noticed that NOW my SubSonic collections were showing up in the Website DataSources window and I could drag and drop the report layout.
So if you are dynamically setting the report datasources at run time and ARE NOT using the ObjectDataSource control already in your project, you MUST add a dummy ObjectDataSource control to one of your aspx pages. This will then make the business object datasources show up in the report designer.

Resources