Simple SubSonic 3 Generation issues - subsonic3

I'm trying to do a proof of concept using SubSonic 3 but Sstraight away i'm hitting numerous errors with the generation. I started making alterations to the generator settings but that seems a little odd when I'm just trying to do a simple one to one mapping of my DB.
Firstly I found an SP that had #delagate as an SP parameter name, this was easily fixed, but should probably be in the standard templates as a user shouldn't have to make template changes for this simple an issue.
Next I found that the system choked on two tables and tried to create signatures the same
the tables where
Field
Fields
now i know SubSonix 2 had a fixPluralClassName property but buggered if I can find one in the template for SubSonic 3
Any help on that one will get me started

Generally 'X' and 'Datum' type appendages/substitutions happen when you have used a 'reserved' word in a column or table name. In this case 'Reserved' being a word that Subsonic doesn't like to use for data objects.
A couple of rules I follow are;
Ensure both table names and column
names are not 'reserved' words (ie
'Data' or 'Int' or 'Table')
Ensure that each table has a primary key
Don't use date and time column types
as they are not supported yet
(DateTime is, just not Date and Time types)
Don't have a column with the same
name as the table
The Subsonic FAQ might be helpful.

Related

Best way to track occurrences of an element using a Database

I'm developing an application that recognizes an element, given a library of models.
This library is saved in a local Database in one table. This table contains the model identification number, its name, and the number of times that it was recognized. This last parameter is used because I developed a specific application for the organization of that library, and I want short all the models by how many time each one was matched.
The application that matches the current element with the models saved in the library, run in the same PC and have access at the model library database.
What is the best way to track the number of occurrences in which a model was recognized with the element under analysis?
One solution can be: execute a query and increment by one the match count value in the model's table every time that I match it, but I'm scared due to the fact that I have to perform a match operation every 2/3 second. With this solution, I will query verbosely the database I think.
Another useful information can be obtained, thanks to the fact that I save in a table in the same database, the history of elements under analysis with their match result for elaboration purpose. Maybe when I start the application referred to manage the model's library, I can count the number of occurrences for each model from the history table and update the model's match count. But I have more or less 20.000 candidates for the matching per day, and I'm planning to clear the history table each day/month, and now a day in this table I don't save the date.
Thanks in advice

Comparing two SQLite databases in C++

I have two C++ functions, which each construct an SQLite database.
First function constructs database version 1, and then upgrades it to newest version by adding all tables/columns that have been added to the database since the first version. Another function constructs a database that is already in the newest version. As result, each function gives one database that has all necessary tables and columns, but no values.
I wish to write an unit test that compares the results of those two functions. I want to test that they have exactly the same tables and columns, and that all columns have the same CHECK and NOT NULL constraints. I only need to compare columns and tables, because the databases have no values in them at this point.
I would prefer to get the differences in a human readable form (to place them in an error message), but a boolean value (different/not different) is also fine.
How can I do that, given that both databases are in different variables and I cannot combine them?
There are other questions that suggest external applications for this, but can I do it in a simple way in C++? One possibility is to execute some SQL commands for each database, and compare the results in a for loop, but which commands do I need?
You can read the sqlite_master table to read the SQL used to create each table and compare that:
SELECT name, type, sql FROM sqlite_master;
For more information on sqlite_master, consult the SQLite documentation.

Django and Oracle nested table support

Can Django support Oracle nested tables or varrays or collections in some manner? Asking just for completeness as our project is reworking the data model, attempting to move away from EAV organization, but I don't like creating a bucket load of dependent supporting tables for each main entity.
e.g.
(not the proper Oracle syntax, but gets the idea across)
Events
eventid
report_id
result_tuple (result_type_id, result_value)
anomaly_tuple(anomaly_type_id, anomaly_value)
contributing_factors_tuple(cf_type_id, cf_value)
etc,
where the can be multiple rows of the tuples for one eventid
each of these tuples can, of course exist as separate tables, but this seems to be more concise. If it 's something Django can't do, or I can't modify the model classes to do easily, then perhaps just having django create the extra tables is the way to go.
--edit--
I note that django-hstore is doing something very similar to what I want to do, but using postgresql's hstore capability. Maybe I can branch off of that for an Oracle nested table implementation. I dunno...I'm pretty new to python and django, so my reach may exceed my grasp in this case.
Querying a nested table gives you a cursor to traverse the tuples, one member of which is yet another cursor, so you can get the rows from the nested table.

borland builder c++ oracle question

I have a Borland builder c++ 6 application calling Oracle 10g database. Operating over a LAN. When the application in question makes a simple db select e.g.
select table_name from element_tablenames where element_id = 10023842
the following is recorded as happening in Oracle (from the performance logs)
select table_name
from element_tablenames
where element_id = 10023842
then immediately (and not from C++ source code but perhaps deeper)
select table_name, element_tablenames.ROWID
from element_tablenames
where element_id = 10023842
The select statement is only called once in the TADODbQuery object, yet two queries are being performed - one to parse and the other adds the ROWID for executon.
Over a WAN and many, many queries this is obviously a problem to the user.
Does anyone know why this might be happening, can someone suggest a solution?
Agree with Robert.
The ROWID uniquely identifies a row in a table so that the returned record can be applied back to the database with any changes (or as a DELETE).
Is there a way to identify a particular column (or set of columns) as a primary key so that it can be used to identify a row without using a ROWID.
I don't know exactly where the RowID is coming from, it could be either the TAdoQuery implementation or the Oracle Driver. But I am sure I found the reason.
From the Oracle docs:
If the database table does not contain a primary key, the ROWID must be selected explicitly when populating DataTable.
So I suspect your Table does not have a primary key, either add one or add the rowid.
Either way this will solve the duplicate query problem.
Since you are concerned about performance. In general
Using TAdoQuery you can set the CursorType to optimize different behaviors for performance. This article covers this from a TAdoQuery perspective. MSDN also has an article that covers it from from a general ADO Perspective. Finally the specifications from the Oracle Driver can be useful.
I would recommend setting the Cursor to either as they are the only supported by Oracle
ctStatic - Bi-directional query produced.
ctOpenForwardOnly - Unidirectional query produced, fastest but can't call Prior
You can also play with CursorLocation to see how it effects your speed.

WQL SELECT with optional column

I need to make a query like this:
SELECT PNPDeviceID FROM Win32_NetworkAdapter WHERE AdapterTypeId = 0
Trouble is, the AdapterTypeId column isn't always present. In this case, I just want everything, like so:
SELECT PNPDeviceID FROM Win32_NetworkAdapter
My WQL/SQL knowledge is extremely limited. Can anybody tell me how to do this in a single query?
EDIT:
A bit more background seems to be required: I am querying Windows for device information using WMI, which uses an SQL-like syntax. So, in my example, I am querying for network adapters that have an AdapterTypeId of 0.
That column is not always present however, meaning that if I enumerate through the returned values then "AdapterTypeId" is not listed.
EDIT 2:
Changed SQL to WQL; apparantly this is more correct.
I am assuming you mean the underlying schema is unreliable.
This is a highly unconventional situation. I suggest that you resolve the issue that is causing the column to not always be present, because to have the schema changing dynamically underneath your application is potentially (almost certainly) disastrous.
Update:
OK, so WQL lets you query objects with a SQL-like syntax but, unlike SQL, the schema can change underneath your feet. This is a classic example of a leaky abstraction, and I now hate WQL without ever having used it :).
Since the available properties are in flux, I am guessing that WQL provides a way to enumerate the properties for a given adapter. Do this, and choose which query to run depending upon the results.
After some Googling, there is an example here, which shows how to enumerate through the available properties. You can use this to determine if AdapterTypeId exists or not.
SELECT PNPDeviceID FROM Win32_NetworkAdapter WHERE AdapterTypeId = {yourDesire} OR AdapterTypeId IS NULL
I assume that you mean that this field is missing from the table.
Do you know before submitting the query if this field exists?
If yes then just create SQL dynamically, otherwise It think you will get syntax error in case of missing field
This is not an SQL question. SQL does not contemplate records with varying schemas in a single table source. Instead (as you mention) this is a different system using an "SQL-like" syntax. You'll have better luck if you recast the question using the actual product that you're trying to query, and information how that product deals with variable record structures is probably discussed in the documentation.