Stored procedure name tagging - stored-procedures

Ever wonder what wikipedia's database schema looks like? I recently read this thread from reddit.
I like how their tables are tagged with a prefix so you can sort of tell its functionality, purpose, and relationship with other tables right off the bat.
One thing I do not notice is how they name their stored procedures. Do they even use SP?
I use MS SQL Server. Prefixing all stored procedures with USP_ or SP_ seems redundant and anti-beneficial as the object explorer already sorts it all out for me. How do you name your SPs?

I like how their tables are tagged with a prefix so you can sort of tell its functionality, purpose, and relationship with other tables right off the bat
That is why you have Schemas in SQL Server, you create a schema to group several object together and then you can give the HR person just access to the HR schema
Prefixing all stored procedures with USP_ or SP_ seems redundant and anti-beneficial as the object explorer already sorts it all out for me. How do you name your SPs?
SP_ should never be use because you will get a performance hit, whenever SQL server 'sees' a proc that starts with sp_ it will check the master database first, worst if MS decided to ship a proc with the sane name as yours and it starts with sp_ yours will never get executed
BTW not everyone is using the project explorer, some people like to do this in T-SQL

I personally will prefix my stored procedures with a unique name the describes what it does. For example.
SelectUserAccountById
or
InsertUserAccount
Typically the table name is referenced in the name, in the example above, the table would be UserAccount.
I do not prefix my stored procedures with SP or anything similar UNLESS I am building an extension that goes into a framework such as DotNetNuke, then I use a prefix for my company name.

I find it useful to name the strored proc as
TableName_Action
example RefClient_Insert, RefClient_Search, RefEmployee_Delete
This way, since the tables are grouped (Ref = Reference in this case) the SPs are grouped too.
Note that I have used _ just for clarity, you may skip it if you like.

I started naming all of the SQL objects with a widget type prefix. For example...
Photo Gallery Database Objects (abbreviated list)
Old Name | New Name
-------------------------------------------------
tblCategories | tblPGCategories
tblItems | tblPGItems
spGetCategories | spPGGetCategories
spUpdateCategory | spPGUpdateCategory
spGetItems | spPGGetItems
spUpdateItem | spPGUpdateItems
Event Calendar Database Objects (abbreviated list)
Old Name | New Name
-------------------------------------------------
tblCategories | tblECCategories
tblItems | tblECItems
spGetCategories | spECGetCategories
spUpdateCategory | spECUpdateCategory
spGetItems | spECGetItems
spUpdateItem | spECUpdateItems
We developed lots of websites and when a customer wanted a piece of functionalty we thought we could sell to others we would create it as a widget. We would then market these widgets to other customers.
This worked great until we started adding widgets we developed from other websites. We wound up with duplicate names for some of our code. So, out of necessity we implement a widget type naming convention. This made it very easy to integrate all the widgets we created.

Related

The Ruby on Rails Way (guidance)

I'm making a RoR app that is going to have a bunch of network diagnostic tools in it, like ping, traceroute, whois, etc. It's an internal company thing. Being that I'm learning Rails, I'd like to create it in that.
So, I'm curious what's the best structure to make this? Would it make sense to have all the tools under one MVC, like 'tools', or to break each one out into their own MVC (i.e., ping_controller & model/ping, traceroute_controller & `model/traceroute', etc.)?
So:
App
|--models
| |--tools (which would just write the `ip`, `tool_type` and `hitcount` to the DB.)
|
|--controllers
| |--tools (which would contain the methods: `ping`, `traceroute`, etc.)
|
|--views
|--tools
|--index.html.erb (which would have the individual form to run a given tool and show results)
Or would it make more sense to break it out more, but still keep the individual tool form elements on the same page and direct them with something like form_for(controller: 'ping', action: 'show'):
App
|--models
| |--ping (which would just write the `ip` and `hitcount` to the DB.)
| |--traceroute (which would just write the `ip` and `hitcount` to the DB.)
|
|--controllers
| |--ping (which would contain the normal CRUD and results)
| |--traceroute (which would contain the normal CRUD and results)
|
|--views
|--tools
|--index.html.erb (which would have the individual form to run a given tool and show results)
What's the "Ruby Way" to do this? I feel like the second option is not very DRY, but I'm still learning... hence my question.
If type is the only difference between each types of tools, I would suggest you to use the first way. If there will be more complex logic/columns differences, I would suggest you to have a look into Single Table Inheritance (STI):
http://samurails.com/tutorial/single-table-inheritance-with-rails-4-part-1/

Error 2002 : The EntityContainer 'X' for the storage model specified as part of this MSL does not exist in MetadataWorkspace

I'm trying to integrate my Oracle Database into my ASP.NET app, but I keep getting this error :
Error 2002: The EntityContainer 'OracleDBTargetContainer' for the
storage model specified as part of this MSL does not exist in
MetadataWorkspace.
I've tried everything I could think of but still can't figure out what's wrong.
What can I do to diagnose the root cause of this?
This is still new to me so I might miss something very obvious.
I'm assuming it my not like my database as the Diagram displayed when I integrated another DB. I've checked the foreign keys, primary keys, ... but to no good.
Using VS2013 with ODP.NET 12c Release 3.
EDIT : My EntityContainerMapping is empty, is that normal?
<EntityContainerMapping CdmEntityContainer="PMModelContainer" StorageEntityContainer="PMModelTargetContainer"></EntityContainerMapping>
I found what was wrong.
One of my foreign key didn't match the primary key (Number 20 instead of Number 10)
I saw on stack overflow that it could be a problem and checked my tables but I missed that one obviously.
How did I realize it ? Well because rather than creating the EF Designer, I chose the Code First from database option, and, oh, what do you know, the error message now tells you EXACTLY what the problem is ! (Table names and columns).

How to map URL requests for vBulletin posts to Drupal 7 Forum comments after migration?

I need help to map requests for vBulletin posts to their new location on a Drupal 7 forum.
I inherited a Drupal site after it was migrated from Drupal 5 with vBulletin, to Drupal 7 with native Drupal Forum + Advanced Forum. The new sit also uses PathAuto.
Every day I get many http requests using the old D5/vBulletin URL scheme, and there is no mapping in place to rewrite the target.
I believe I can use Apache mod_rewrite or Drupal Global Redirect to handle this, if I can map the old system to the new one.
For requests for "thread", e.g. example.com/forums/showthread.php?t=1 it seems possible to map, because the Drupal 7 path alias to the node for the thread has already been created using the existing node's title. So I can look up in the vBulletin database the old node title using the incoming query's 't' argument, edit that string according to the PathAuto settings in use on the new system, and create a URL alias. [Would love to know if there's a better way.]
But for incoming requests for "post", e.g. example.com/I can't see how to do it. The vBulletin database has the posts in the "post" table, but in Drupal 7 Forum anything after the initial post is a "comment" and has not had a URL alias created for it (because it doesn't have a title in vBulletin in most cases).
I suppose I could find the thread that the post belonged to and redirect the user to the top of the thread, as a workaround, but I'd like to have an accurate map.
Please any solutions for this ?
Drupal Migrate creates and saves tables in the database mapping the old resource ID to the new ID.
You just have to be careful since the schema are different between vBulletin and Drupal Forum; primarily in that Forum posts in D7 (other than the first post in a thread) are not nodes, but comments.
But I was able to use a Join SQL query to find the new resource ID:
mysql> SELECT m.sourceid1, m.destid1, c.cid, c.nid, c.subject FROM migrate_map_forum_posts m LEFT JOIN comment c ON c.cid = m.destid1 LIMIT 3;
+-----------+---------+-------+-------+-----------------+
| sourceid1 | destid1 | cid | nid | subject |
+-----------+---------+-------+-------+-----------------+
| 2 | 35837 | 35837 | 10426 | RE: Test |
| 3 | 35838 | 35838 | 10426 | |
| 4 | 35839 | 35839 | 10426 | I see a picture |
+-----------+---------+-------+-------+-----------------+
This solution only relies on the new Drupal 7 database and that's okay if the migration went perfectly (I guess if it was perfect the mapping would have been done at the time, lol). But the migration map tables don't always have all the data you need.
If you have access to the old vBulletin database you can dig deeper. In the migration that I inherited, some of the vBulletin 'posts' did not make it into the D7 migration map tables. But through doing more queries I was able to get the 'threadid' that the post belonged to from the vBulletin database and find the node ID for the Forum topic on D7 so I can at least get the user on to the right discussion.

Umbraco, Orchard: Content from custom Table

I am currently investigating the possibilities of different CMSs for a company-site. Done quite a few projects in classical ASP, ASP.NET, Joomla etc..
I would like to use Umbraco or Orchard for the first time.
For that project we have a SQL-Table with Departmenst and a second with Job-Opportunities: like: JobName, DepartmentID, Description, etc..
So a 1:n relationship.
A first page should list Departments with links to sub-pages of Jobs available
These should be listed on a second page.
In ASP.NET I would use something like a Repeater, etc.. with PageSize option and automatic paging.
In the Backend (Backoffice in Umbraco, I assume) there has to be an Insert/Edit/Delete Page with the corresponding input boxes, which are maintained by the company employees, not by web-developers.
So in both cms I try to accomplish an Access-like table-form in the backend like:
Job | Description | ....
Job1 | descr1 | ....[edit][delete]
Job2 | descr2 | ....[edit][delete]
Job3 | descr3 | ....[edit][delete]
[New Job]
Which route should I look at? I am completely stuck, is there an example anywhere? Can I use my own data-tables, or could/should I use the built-in content tables for this?
Thank you, Reinhard
This sounds relatively straightforward, in Umbraco anyway, you could use either the built-in content tables, or else use straight SQL server tables and write the code to 'talk' to the db yourself.
The benefit of using the content tables in Umbraco however, is that everything else will be easier to do; everything else in the system is designed to just use those content tables with no extra coding...unless you have a tremendous amount of data, or some special requirements you haven't mentioned, I would definitely fully explore the possibility of just using the built in Umbraco functionality for this, before deciding to roll-your-own custom tables within umbraco.
Its possible, and not that hard, but is is extra work that you shouldn't do unless necessary.
Not familiar with Orchard, so can't comment on that.

Propel wrong table prefix with external schema

I am using propel orm as database abstraction layer.
I want to define different schema.xml files for diffenrent modules.
E.g. user.xml.schema for handling users and roles, or app.schema.xml for the application model.
My problem is, I want to reference to the user table of the user.schema.xml. I can handle this by the tag, but I want to use another table prefix for the user schema tables.
Running propel-gen creates two sql files (one for the user.schema and one for the app.schema), but the problem is, that the user-schema tables are generated twice. First with correct table prefix of the user schema file and the others with the prefix of the app schema file.
The foreign key also references to the wrong tables (that from the table with the prefix of the app.schema.xml).
I do not know any way to prevent this behaviour.
Any hints?
You cannot add different table prefixes to one database, and there is no way to add a tablePrefix attribute on the table tag. Let me explain a bit more, I know, you can specify a tablePrefix per XML schema even for a same database, but it leads to errors if you try to add relationship.. I don't know whether it's a bug or not, AFAIK the tablePrefix should be defined at the table level… Without relationship, you'll get a clean SQL file (or two if you don't set the propel.packageObjectModel build property to true.
You can read: http://www.propelorm.org/reference/schema.html. So I think, it's not possible to do what you would like to do unfortunately.
BTW, what you want to achieve is called multi component data model in the Propel doc.

Resources