Is it possible to search for all dependencies of a field - firebird

I am searching for a specific line in my database and wanted to know if there is a function in ibexpert to look up for all dependencies of a field.

I don't know IBExpert, but generically in Firebird, you can find dependencies in the system table RDB$DEPENDENCIES. It won't tell you exactly on which line of code a field is used, but it will help you identify in what object it is used. Then it is a matter of inspecting the source code of that specific object to see where it's used.
The table RDB$DEPENDENCIES has the following columns (in Firebird 2.5):
RDB$DEPENDENT_NAME - The name of the 'dependent' (the object using the dependency), eg a stored procedure name
RDB$DEPENDED_ON_NAME - The name of the dependency (eg table name)
RDB$FIELD_NAME - The field name of a dependency (eg table column); can be NULL for non-field dependencies
RDB$DEPENDENT_TYPE - Type of the dependent (eg 0 = relation (table or view), see RDB$TYPES with RDB$FIELD_NAME = 'RDB$OBJECT_TYPE for possible values)
RDB$DEPENDED_ON_TYPE - Type of the dependency (column dependencies have type 0 and RDB$FIELD_NAME not null, table/view dependencies have type 0 and RDB$FIELD_NAME null.
As an example, you can use the following query:
select dep.*, tt.RDB$TYPE_NAME as DEPENDENT_OBJECT_TYPE, dt.RDB$TYPE_NAME as DEPENDED_ON_OBJECT_TYPE
from RDB$DEPENDENCIES dep
inner join RDB$TYPES tt
on tt.RDB$TYPE = dep.RDB$DEPENDENT_TYPE
and tt.RDB$FIELD_NAME = 'RDB$OBJECT_TYPE'
inner join RDB$TYPES dt
on dt.RDB$TYPE = dep.RDB$DEPENDED_ON_TYPE
and dt.RDB$FIELD_NAME = 'RDB$OBJECT_TYPE'

When field is selected in table click on "Field dependencies" tab.

Related

SQL query to extract default (initial) value of a value property

I am trying to create a custom template fragment that builds a table of value properties. I started by creating a SQL query fragment that pulls all properties classified by a Value Type. Now I would like to pull in the default (initial) value assigned. I figured out that it's in the Description table of t_xref, with the property guid in the client field, but I don't know how to write a query that will reliably parse the default value out since the string length may be different depending on other values set. I tried using the template content selector first but I couldn't figure out how to filter to only value properties. I'm still using the default .qeax file but will be migrating to a windows based DBMS soon. Appreciate any help!
Tried using the content selector. Successfully built a query to get value properties but got stuck trying to join and query t_xref for default value.
Edited to add current query and image
Value Properties are block properties that are typed to Value Types. I'm using SysML.
This is my current query, I am no SQL expert! I don't pull anything from t_xref yet but am pulling out only the value properties with this query:
SELECT property.ea_guid AS CLASSGUID, property.Object_Type AS CLASSTYPE, property.Name, property.Note as [Notes], classifier.Name AS TYPE
FROM t_object property
LEFT JOIN t_object classifier ON property.PDATA1 = classifier.ea_guid
LEFT JOIN t_object block on property.ParentID = block.Object_ID
WHERE block.Object_ID = #OBJECTID# AND property.Object_Type = 'Part' AND classifier.Object_Type = 'DataType'
ORDER BY property.Name
I guess that Geert will come up with a more elaborate answer, but (assuming you are after the Run State) here are some details. The value for these Run States is stored in t_object.runstate as one of the crude Sparxian formats. You find something like
#VAR;Variable=v1;Value=4711;Op==;#ENDVAR;
where v1 is the name and 4711 the default in this example. How you can marry that with your template? Not the faintest idea :-/
I can't give a full answer to the original question as I can't reproduce your data, but I can provide an answer for the generic problem of "how to extract data through SQL from the name-value pair in t_xref".
Note, this is heavily dependent on the database used. The example below extracts fully qualified stereotype names from t_xref in SQL Server for custom profiles.
select
substring(
t_xref.Description, charindex('FQName=',t_xref.Description)+7,
charindex(';ENDSTEREO',t_xref.Description,charindex('FQName=',t_xref.Description))
-charindex('FQName=',t_xref.Description)-7
),
Description from t_xref where t_xref.Description like '%FQName%'
This works using:
substring(string, start, length)
The string is the xref description column, and the start and length are set using:
charindex(substring, string, [start position])
This finds the start and end tags within the xref description field, for the data you're trying to parse.
For your data, I imagine something like the below is the equivalent (I haven't tested this). It's then a case of combining it with the query you've already got.
select
substring(
t_xref.Description, #the string to search in
charindex('#VALU=',t_xref.Description,charindex('#NAME=default',t_xref.Description)+6, #the start position, find the position of the first #VALU= tag after name=default
charindex('#ENDVALU;',t_xref.Description,charindex('#VALU=',t_xref.Description))
-charindex('#VALU=',t_xref.Description,charindex('#NAME=default',t_xref.Description))-6 #the length, find the position of the first #ENDVALU tag after the start, and subtract it from the start position
),
Description from t_xref where t_xref.Description like '%#NAME=default%' #filter anything which doesn't contain this tag to avoid "out of range" index errors

Search jsonb fields in postgresql with Hasura

Is it possible to do a greater than search across a jsonb field using hasura?
it looks to be possible in PostgreSQL itself, How can I do less than, greater than in JSON Postgres fields?
in postgres I'm storing a table
asset
name: string
version: int
metadata: jsonb
the metadata looks like this.
{'length': 5}
I am able to find asset that matches exactly using the _contains.
{
asset(where:{metadata : {_contains : {length: 5}}}){
name
metadata
}
}
I would like to be able to find asset with a length over 10.
I tried:
{
asset(where:{metadata : {_gt : {length: 10}}}){
name
metadata
}
}
A. Possibility to do on graphql level directly
Hasura documentation: JSONB operators (_contains, _has_key, etc.) mentions only 4 operators:
The _contains, _contained_in, _has_key, _has_keys_any and _has_keys_all operators are used to filter based on JSONB columns.
So direct answer for your question: No. It's not possible to do on graphql level in hasura.
(At least it's not possible yet. Who knows: maybe in future releases more operators will be implemented.
)
B. Using derived views
But there is another way, the one explained in https://hasura.io/blog/postgres-json-and-jsonb-type-support-on-graphql-41f586e47536/#derived-data
This recomendation is repeated in: https://github.com/hasura/graphql-engine/issues/6331
We don't have operators like that for JSONB (might be solved by something like #5211) but you can use a view or computed field to flatten the text field from the JSONB column into a new column and then do a like on that.
Recipe is:
1. Create a view
CREATE VIEW assets -- note plural here. Name view accordingly to your style guide
AS
SELECT
name,
version,
metadata,
(metadata->>'length')::int as meta_len -- cast to other number type if needed
FROM asset
2. Register this view
3. Use it in graphql queries as usual table
E.g.
query{
assets(where: {meta_len: {_gt:10}}){
name
metadata
}
C. Using SETOF-functions
1. Create SETOF-function
CREATE FUNCTION get_assets(min_length int DEFAULT 0)
RETURNS SETOF asset
LANGUAGE SQL
STABLE
AS $$
SELECT * FROM asset
WHERE
(metadata->>'length')::int > min_length;
$$;
2. Register in hasura
3. Use in queries
query{
get_assets(args: {min_length: 10}){
name
metadata
}
I think that was the last possible option.
It will not gives you full "schemaless freedom" that maybe you're looking but IDK know about other ways.

Eclipse db2 xml column return value is a object address

I use Eclipse(Oxygen.2) in the Company.
In my database i have a column and it's typ XML.
If I make a SELECT query my return value is object address com.ibm.db2.jcc.am.re#23717212 but I want to have xml index.
What i did :
Open the Eclipse
File-> New Database Connection
Write the Query : Select * from benutzer;
In the message column i have object-ID(com.ibm.db2.jcc.am.re#23717212).
What i need is the index from XML not object-ID.
Apparently the result set grid in Ecliplse does not know how to render the XML data type and simply uses the toString() method. Let Db2 do the job and, as Mark Barinstein suggested in comments, use the XMLSERIALIZE() function to convert XML to a string:
SELECT XMLSERIALIZE(message as VARCHAR(4000)), -- your other columns
FROM BENUTZER
Adjust the target VARCHAR length as necessary.
The problem was the libraries.
I had two libraries : db2jcc.jar and db2jcc4.jar.
The firstone (db2jcc.jar) has blocked the secondone (db2jcc4.jar).
If I remove the first driver then i can see the xml index.
If I change the sequence i can also see the index form xml file.
That was what i need.
cast to char to view the xml.
select xmlserialize(myxmlcolumn) as myxml from mytable

SQL Server Dependencies missing

This may be a case of my ignorance to what is meant by a dependency.
When I run the following query I get a slightly different list (more entries) to when I chose the menu option View Dependencies (first node level only) why would that be? I should add I am ignoring VIEW dependencies, for example I have a 2 foreign key relationships set up to 2 different tables (pretty much identical configuration) yet only 1 is shown in the View Dependencies yet both a seen in the following query.
I got this off some other post:
SELECT DISTINCT
pt.object_id PrimaryTableID, pt.name PrimaryTableName
FROM
REPDEV.sys.foreign_keys fk
JOIN
REPDEV.sys.tables ft ON fk.referenced_object_id = ft.object_id
JOIN
REPDEV.sys.tables pt ON fk.parent_object_id = pt.object_id
WHERE
ft.name = 'MyTable'
ORDER BY
2
Am I suppose to use other means to get table relationship dependencies?
Include full outer join instead of join (inner join) and add the clause
"fk.name is not null" in where.
Tell me if works :)

ERROR: operator does not exist: character varying = numeric

So I keep getting the title error. The string I am using to create the query is,
select p from Product p where p.productType.productTypeId in (:productTypeIds)
And here is a clip of the java
List<Long>partTerminologyIds = getProducTypeds(partTerminologys);
..........................................................................
query.setParameter("partTerminologyIds", productTypeIds);
I have no idea why I am getting this error, ane yes partTerminolgyId in my database is a numeric 18.
Any ideas???
So in the end it ended up being that a "foreign key" was a string in one table and an numeric in the other. I rebuilt the database with new scripts and did not reverse engineer the new database.
This query is invalid:
select p from Product p where p.productType.productTypeId in (:productTypeIds)
Do you mean:
SELECT p FROM product p WHERE p.productTypeId IN (:productTypeIds)
Or rather:
SELECT * FROM product p WHERE p.productTypeId IN (:productTypeIds)
And if so, what is the data type of productTypeId in your query. Please clarify.
This looks like a Hibernate query. You need to do query.setParameterList to specify a collection value, otherwise Hibernate won't know to expand out :productTypeIds to a list of placeholders instead of simply binding the list as a serializable blob (which I think is an awful default).