How to find the list of the "Oracle interfaces" - oracle

In order to create my own aggregate function, I must :
define an object that have 4 methods.
STATIC FUNCTION ODCIAggregateInitialize( ... ) ...,
MEMBER FUNCTION ODCIAggregateIterate(...) ... ,
MEMBER FUNCTION ODCIAggregateMerge(...) ...,
MEMBER FUNCTION ODCIAggregateTerminate(...)
That means implementing an interface with these 4 functions.
I can now define my aggregate function:
function f (argument integer) return integer using myobject.
to create a polymorphic table function,
I must :
implement a package that implement the funciton describe.
FUNCTION describe (tab IN OUT DBMS_TF.table_t,col IN dbms_tf.columns_t) RETURN DBMS_TF.describe_t;
That means implementing an interface with this function
open,fetch_rows,close are not compulsory.
I can now define a polymorphic table functoin like that
FUNCTION my_ptf(tab IN TABLE,col IN COLUMNS) RETURN TABLE PIPELINED ROW POLYMORPHIC USING my package;
I would like to know if there is other interfaces that I can implement and to do what?
I'm searching a list of these interfaces.

Related

Does eloquent pivot tables work for multi-word table names?

I have two multi-word models, let's call them FunkyModel and AnotherModel.
Will creating a pivot table named another_model_funky_model work?
The docs and examples I've come across all use single word model names like this: model A - User, model B - Address, and pivot table will then be address_user.
If you dive into the source code of the BelongsToMany relation function, you'll find that if you haven't provided a $table, the code will execute the function joiningTable. This uses the current model and the passed related class, snake cases the names and then puts them in alphabetical order of each other.
Simply said, no matter if you have a single word or a couple, the result will always be the 2 classes snaked, in alphabetical order. Note that the alphabetical order is applied by the default php sort.
Examples:
Department + Occupation > department_occupation
AwesomeModel + LessInterestingModel > awesome_model_less_interesting_model
Role + UserPermission > role_user_permission
You can even try and see what the auto-generated name is by simply calling the following:
(new Model)->joiningTable(OtherModel::class, (new OtherModel));
Yes it would work, you can also name it whatever you want, you just need to declare the table name in the relation (same goes for the foreign keys)
class FunkyModel
{
public function anotherModels()
{
return $this->belongsToMany(AnotherModel::class, 'pivot_table_name', 'funky_model_id', 'another_model_id');
}

Laravel/Eloquent get all appointments from a polymorphic "member_id" through a appointment_members table

I have an appointments table and an appointment_members table and my users need to be able to get a collection of appointments by searching with a "member_id", which could be a Person, Incident or CustomerID. The appointment_members table has member_id and appointment_id columns, so the member_type (also a column) is irrelevant. This all set up by a previous dev and what is missing are the relationships on the Eloquent models. I'm just creating a simple GET route that needs to return any/all appointments by that member_id. Each row has one appointment, so if I were to pass in a member_id that returned 10 results, some could have appts and others not, but at the end of the day I just need a collection of appts that are related to that member_id. Here's a screenshot of the appointment_members table:
If I create a simple hasOne relationship to appointments on appointment_members:
public function appointments()
{
return $this->HasOne(Appointment::class, 'id', 'appointment_id');
}
I can get a collection of appointment_members with it's respective appointment, but not sure how I boil it down to just getting the appointments. One workaround I have is to use that HasOne and then pluck/filter the appointments:
$appointmentMembers = AppointmentMembers::where('member_id', $request->input('memberId'))->get();
$appointments = $appointmentMembers->pluck('appointments')->filter();
Curious if anyone might see a better way to go about this. Thanks!
I'm possibly not understanding, but I would probably take the simplest approach here if the member type is not important.
The table is already set up to handle either a belongsToMany or a morphMany, so create the relationship on the Member class (or if you don't have a parent member class, stick it on each of the types Person, Incident, etc. You can also do this via poly, of course, but this is a simple example to get what you need):
public function appointments()
{
return $this->belongsToMany(Appointment::class)->withPivot('member_type');
}
And then just query on the member object you need appointments for (having poly would make this one step):
$allAppointmentsForID = $member->appointments();
$appointments = $allAppointmentsForID->wherePivot('member_type', $whateverClassThisIS);
The above takes member_type into account. If this doesn't matter, you can just use the top line.
Your original db is setup to handle polymorphic relations, so if you wanted more than the appointment you can set it up this way as well. For now, you'll need to add the TYPE to the query to cover the different classes.
If the member type is important, polymorphic might be something like this on the Member class:
public function appointments()
{
return $this->morphMany(Appointment::class, 'memberableOrmember_typeOrWhatever');
}
Then you can query on the member object with just one line
$appointments = $member->appointments();

FUNCTION in WHERE clause of SQL query

I have the following (private) PL/SQL function (inside PACKAGE) returning the previous month in 'YYYYMM' format:
FUNCTION GET_PREV_MONTH RETURN VARCHAR2 IS
BEGIN
RETURN TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYYMM');
END GET_PREV_MONTH;
I need to compare if records are from previous month in several my queries so I wanted to make private function returning previous month. Why I cannot use this return value from GET_PREV_MONTH() function in WHERE clause of my other SQL queries like:
UPDATE mytable t SET t.col=1
WHERE TO_CHAR(t.created,'YYYYMM')=GET_PREV_MONTH();
Oracle says PLS_00231: function 'GET_PREV_MONTH' may not be used in SQL.
If I create this, this works!
UPDATE mytable t SET t.col=1
WHERE TO_CHAR(t.created,'YYYYMM')=TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYYMM');
I wanted to make private function returning previous month. Why I cannot use this return value from GET_PREV_MONTH() function in WHERE clause of my other SQL queries
It is a private function - you cannot reference it outside the package.
If you want to use it in SQL then declare it in the package specification so that it is public.
This is private function of this package! This function is used in procedures from the same package. It is not referenced outside this package.
It CANNOT be used in the SQL context if it is not a public function; regardless of whether the SQL is being called from inside or outside the same package.

Call to a member function addEagerConstraints() on integer

I tried to eager load a relation:
$tournaments = Tournament::with('numCompetitors')->latest()->paginate(config('constants.PAGINATION'));
My relation in Tournament returns an integer:
public function numCompetitors()
{
return $this->competitors()->count(); // it returns 24
}
With that I get:
Call to a member function addEagerConstraints() on integer
I don't understand why is it failing.
You're doing it wrong. If you want to count relationship, use withCount() with properly defined relationship:
Tournament::withCount('competitors')->latest()->paginate(config('constants.PAGINATION'));
If you want to count the number of results from a relationship without actually loading them you may use the withCount method, which will place a {relation}_count column on your resulting models.
https://laravel.com/docs/5.4/eloquent-relationships#counting-related-models

How Can I get return values returned by stored procedure using InsertOnSubmit in LINQ

Can I get return values returned by stored procedure using InsertOnSubmit in LINQ.
The stored procedure return a error number. How can I get this error number InsertOnSubmit (using stored procedure instead of Runtime sql). Many Thanks
On the data-context are a number of partial methods for insert/update/delete of each entity type; if you implement the other half of this, you can provide your own SP logic:
partial class MyDataContext {
partial coid UpdateMyEntity(MyEntity instance) {
// your ADO.NET code and/or ExecuteCommand here...
}
}
Note that if you use a separate connection you won't have the same transaction etc (unless it uses TransactionScope).
I overloaded the default function generated by LINQ designer and followed the below steps.
Created a public readonly property _ReturnCode
In the overloaded function I used _ReturnCode = CType(result.ReturnValue, Integer)
Public Function FUNC_NAME( ByRef .....
Dim result As IExecuteResult = Me.ExecuteMethodCall(Me, CType(MethodInfo.GetCurrentMethod, MethodInfo), ......)
ID= CType(result.GetParameterValue(0), System.Nullable(Of System.Guid))
_ReturnCode = CType(result.ReturnValue, Integer)
Return CType(result.ReturnValue, Integer)
End Function
Let me know if anybody has a better answer. Many Thanks

Resources