How Change TableSchema Programatly ?


Author
Message
Elio Reyes
Elio Reyes
StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)
Group: Forum Members
Posts: 46, Visits: 251


HI



I'm using a 3rd party database, in the database design they put Schema as a company and in my SF application I have to change depends to the company I going to work to, but I do when I fill the BO and it still using the TableSchema property made by the BO Build.



Public Overrides ReadOnly Property TableSchema() As String

Get

Return "P_T_P"

End Get

End Property



Any suggestions how to change this are welcome.



Thanks SF

Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Pedro,

If you are using a base BO you can overwrite the TableSchema property and use whatever schema you want in that method.  I guess you will have the company information somewhere which will be used as the schema. 

Also make sure that any custom FillBy method you create, uses the BO.TableNameAndSchema property.  I have a method I use in all my BOs to get all Records like this:

Public Sub FillAllRecords()

     Using cmd As New SqlCommand()

          cmd.CommandText = String.Format("Select * From {0}", Me.TableNameAndSchema)

          Me.FillDataTable(cmd)

     End Using

End Sub



Edhy Rijo

Elio Reyes
Elio Reyes
StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)
Group: Forum Members
Posts: 46, Visits: 251
I have the information in a table, how can I OverWrite the all BO Methods with the information in my table, because a do something :



Public Sub FillAll(ByVal cTableSchema As String)



Me.FillDataTable("SELECT * FROM " & cTableSchema & ".OP_OPER_DET_MO WHERE ORDEN_PRODUCCION IN " & _

" (SELECT ORDEN_PRODUCCION FROM " & cTableSchema & ".ORDEN_PRODUCCION WHERE ESTADO='L' ) AND OPERACION = 'GALERA' ORDER BY ORDEN_PRODUCCION")

End Sub




I send to all my filldata the schema, but it does not work.



If you can show me how to averwrite



Thanks SF
Elio Reyes
Elio Reyes
StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)
Group: Forum Members
Posts: 46, Visits: 251
Sorry it works, the problem is when I save usisng the save method bo.save()
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Well, if you are going to take a base level approach, then you need to create a BaseBO that all of your BOs inherit from instead of directly inheriting from BusinessLayer.  Then you could implement core base logic to redirect the table schema.  Since I don't really know what you are trying to do, I can't give you a straight answer here.  You are talking about a 3rd party database.  So are you creating your own DbDataSourceItem or trying to make an existing one work?  If you are trying to talk to a 3rd party database then I would recommend creating your own DbDataSourceItem that has all of the this logic within it.  If the logic for this database is closest to SqlServer, the copy over the SqlDataSOurceItem class and start from there.  If it is closest to OLEDB the copy over the Vfp ro AccessDataSourceItem and do the same. 

I really don't have enough information to give you any direct answers, but maybe some of these ideas will get you going in the right direction depending upon your needs.

Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Pedro Hernández (12/04/2008)
Sorry it works, the problem is when I save usisng the save method bo.save()

Pedro,

Probably there are some methods in SF which will use the TableSchema property of the BO, and in your code you are not updating this property, then it will return the schema of the table which was selected at the time of the BO generation by the BOM.

Like I said before, in your base BO class, simply override that property to return the value of your custom schema, something like this:

Public Overridable ReadOnly Property TableSchema()

     Get

          Return GetCustomSchemaName()

     End Get

End Property

Private Function GetCustomSchemaName() As String

     '-- Add your logic here to return your Schema Name from your source.

     Return "Your Schema Name"

End Function

Or if you want to make is simpler, don't create the GetCustomSchemaName() function and add that logic in the "Get" of the TableSchema property.  If you don't have a base BO, then you will need to do the same for all the BO you create, so it is a best practice to have your own base BO class.

And in your Fill command try to use the propertys of the BO available to you like the TableSchema, so your method may look like this:

Public Sub FillAll()

     Me.FillDataTable("SELECT * FROM " & Me.TableSchema & ".OP_OPER_DET_MO WHERE ORDEN_PRODUCCION IN " & _

" (SELECT ORDEN_PRODUCCION FROM " & Me.TableSchema & ".ORDEN_PRODUCCION WHERE ESTADO='L' ) AND OPERACION = 'GALERA' ORDER BY ORDEN_PRODUCCION")

End Sub

Of course, I have not try the above, it is mean to give you an idea to explore.

Edhy Rijo

Elio Reyes
Elio Reyes
StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)
Group: Forum Members
Posts: 46, Visits: 251
Hi



I'm sorry for my bad exexplanations



I fill the Bo's nice, because I send then a parameter with the Schema, my problem is with SF internals instructions like save(), BrowseDialog..... because I can't tell then wichwhichema use, And of course they use the one when I make with the Business Object Mapper.



I need to change this too.



Thanks SF
Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Pedro Hernández (12/04/2008)
Hi

I'm sorry for my bad exexplanations

my problem is with SF internals instructions like save(), BrowseDialog..... because I can't tell then wichwhichema use, And of course they use the one when I make with the Business Object Mapper.

Your explanations are OK, but it looks like you are not reading the replies properly Hehe, the answer is right there for you, by working with the TableSchema property.

Edhy Rijo

Elio Reyes
Elio Reyes
StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)StrataFrame Beginner (46 reputation)
Group: Forum Members
Posts: 46, Visits: 251
Excellent information, I know that I asking so much, I have VB concept problem, because I need to change the Schema in runtime, I was thinking in a global variable, but I don’t know how to this, is the way that I found to change the schema when the user change the company running the application.



Any suggestion is appreciate



Thanks a Lot for your time and your very important information



SF

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Perdo,



I think they are suggesting that in your BaseBO (if you aren't using one, now would be the time), you override the TableSchema property. Within it, you would then code the logic to change the db schema based on company. You could go about getting the company within the TaleSchema property in a number of ways. You would also add a company property to the BaseBO, or you could have a shared class that provide the current company info...I'm sure there are other ways too. Does that make more sense?
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search