Find and replace all links in database - sql-server

I want to find and replace in all db fields which contains a link in my database?how is that possible?
I have more tables but i don't know which tables :),i need to search programmatically.
I need to a method,example,GetContainsaLink(dbname) it should returns me tables and which field contains a link,
I have already a dictionary map old and new link for changing.
Example:
old link in a db field :images/123/789/picture/9D/10006685.jpg
new link in a db field :images/345/8001/picture/9D/10006685.jpg

Dump your from -> to mapping into a new table, and perform updates such as the below:
UPDATE MLT
SET link = LM.newlink
FROM mylinktable MLT
INNER JOIN linkmap LM
ON LM.oldlink = MLT.link
...to find which fields need updating - now that requires some knowledge of the data you're storing. A query such as SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE '%link%' may be useful here.

Related

How to distinguish tables from views using Metadata in SQLAlchemy?

I am using SQLAlchemy to describe my database content. I am using Metadata object, reflect method and looping over tables. (Code below)
When I am looping over the tables I need to distinguish which one of them is a table and which one is a view. I can't seem to find any attributes or method that could help me.
metadata = MetaData(bind=self.engine, schema=schema)
metadata.reflect(views=True)
for key, table in metadata.tables.items():
print(table.name)
# Here I need to know if table is a table or a view
I tried printing the type of the table object, but it's always type sqlalchemy.sql.schema.Table
Thanks!
I don't think that SQLAlchemy distinguishes between tables and views - both are Table instances. A workaround - at the cost of an extra query - might be to compare the results of reflecting with and without views:
tmeta = metadata.reflect(engine)
vmeta = metadata.reflect(engine, views=True)
view_names = vmeta.tables.keys() - t.meta.tables.keys()

Implement a CONTAINS (IN) in DB2?

I have a DB2 9.X table with a column named summary.
Here's an example.
SUMMARY
updated www.name1.do.com
Went from www.there2.do.com towww.here1.do.com
Backed up theretherethere.do.this.com and restored to hellothereworld.go.com
Those are three different rows.
In my program I've got a list of URLs. I need to search the database in a way that returns all the rows if the summary column CONTAINS any of the URLs in my list.
Thanks
Store your URLs in a table (i.e. urls) and put '%' round your urls (i.e. %www.name1.do.com%) join both table using a cross join and select like this:
select summary
from basetable, urls
where summary like urls.likecolumn

MS Access default value from another table

I have two tables in a database. One is called salesreceipt and the other is salesreceiptlinedetail.
Each row in salesreceiptlinedetail has a field IDKEY that matches a field TxnID in a row in salesreceipt. There can be multiple rows in salesreceiptlinedetail that can match the same row in salesreceipt.
I have third party software that syncs my access database with Salesforce. The software only allows querying one table in the database at a time.
I need to automatically copy some of the fields from the salesreceipt table to new fields in the salesreceiptlinedetail table so I can sync the data correctly.
I'm very new to MS access. After trying many different things I landed on a solution that I think may work but I'm not sure how to do it. It looks like I can set the default value of a field. I'm thinking I need to do a DLookup to find the field I want to copy in the salesreceipt table and somehow use criteria to check the IDKEY matches the TxnID. I think I need to create a module with a function to do this but I'm not sure how and how to call it.
I may be way off on this. I could use some help or ideas. I've been researching for hours and could use a little push in the right direction. Thanks in advance.
Here's some things you can try, though I'm making some assumptions about the tables you've got and the result you're looking for.
So you've got a table called salesreceipt with an ID field TxnID and some other data (e.g. CustomerRef_FullName):
And then you've got a salesreceiptlinedetail table that has a field IDKEY field that matches back to salesreceipt table's TxnID field (i.e. a foreign key) and an empty field (e.g. FullName) that you want data for by matching the record back to the salesreceipt table.
I can think of a few ways of achieving this so that you end up with a table that has the information you want, but I'm not sure which is best for you. All these options shown are using Access 2013.
1) Get the data using a SELECT query and export those results across to your third-party software:
In Access, go to Create / Query Design:
Add your salesreceipt and salesreceiptlinedetail tables to your query and then close the Show Table window:
Click and drag on the TxnID field to the IDKEY field to create a join (represented by a line in Access):
Double-click on the IDKEY from your salesreceiptlinedetail and CustomerRef_FullName from your salesreceipt table; they should show as fields in the area at the bottom (if you have other fields you need then add those too, I'm just going on 1 field for illustrative purposes):
Click run to see the result of this query:
Hopefully this is showing a table that's starting to fill-in the blanks you want:
You can then save the query (right-click on the query table and chose "save" and name it whatever you want):
And export the results to a spreadsheet (assuming spreadsheet is the format your third-party software takes). Go to External Data / and then click "Excel" from the export group:
The query with the name you saved it as will be there in the Access Objects side-bar so that you can run it and export the results again (double-click on it to run it again):
The good thing about this method is that it's faster than using DLOOKUPs (these can be resource-heavy if you have a lot of records) and if there is new data/records in your salesreceipt and salesreceiptlinedetail tables, the query will run on that new data and include it in its results without you having to modify the query.
For your question though, it sounded like you might want to populate your salesreceiptlinedetail table with the data you need... this SELECT query will not do that. If you want to populate the actual salesreceiptlinedetail table you will need an UPDATE query...
2) Populate empty fields in salesreceiptlinedetail using an UPDATE query matched to records from salesreceipt
In this example, we're going to populate an empty field in salesreceiptlinedetail, namely the FullName field. We're going to do this by matching records in salesreceiptlinedetail to salesreceipt using the IDKEY and TxnID fields and then bring across the corresponding data in the CustomerRef_FullName field to the FullName field.
To do this, setup a new query the same way we did in (1) above and stop after you complete this stage:
Change the Query Type to an "Update" query:
Double-click the empty field you want to populate, e.g. FullName from the salesreceiptlinedetail table:
In the "Update To" box, type the name of the corresponding table and field you want to use to populate your empty field. Enclose the table and field each by a pair of square brackets and separate each by dot. So it should look something like this:
[salesreceipt].[CustomerRef_FullName]
In the criteria box, match your IDKEY and TxnID fields, like this:
[salesreceiptlinedetail].[IDKEY]=[salesreceipt].[TxnID]
Click "Run" and Access should show a warning that it is about to update some records in a table. Click Yes to allow it to do this:
If you go back to your salesreceiptlinedetail table, you should see that the once empty FullName field is now populated:
You can then save your UPDATE query for use again later - be aware that double-clicking on the query will open it AND run the UPDATE again (i.e. it will attempt to populate your salesreceiptlinedetail table with new data), so if you don't want that to happen you can right-click on it and open it Design View before opting to run it.
This method is good if you want to populate data in an already existing table, rather than essentially building a new table of results out of existing tables as described in (1) when we used a SELECT query.
If there's new data in salesreceiptlinedetail or salesreceipt, you'll want to run this UPDATE query again.
This is to add to Matt's answer. We have similar situations for a miniature reporting database, where we need to update the database several times through out the day. We wrap the query in a function and schedule a task in Windows to run every 4 hours that executes the Access function and updates the data.

Which table are Aliases stored in?

In Sitecore I have created an alias called "bob" for a page.
For most items in Sitecore, the data is saved in the Items table in the database. You can easily see these if you search using the Item ID.
However whenever I search for an alias it returns no results:
select * from Items where ID ='0134A009-5D38-43C1-96C6-33C305543B7B'
Are aliases stored in a different location?
I have tried manually looking through all the tables and also ran a script which should search the whole database. If it is stored there then it looks like it is not in plain text.
Aliases like any other items are stored in the Items table.
You should check if you're looking for the Alias in the proper database. Maybe You're checking core or web database instead of master?
I've created a Bob alias in my env and query below returns 1 row containing alias details:
SELECT
*
FROM
[dbo].[Items]
WHERE
ID = '03275C36-32CE-47F7-AD28-9D5D2649E934'

How to do an initial batch import of CSV / MySQL data into neo4j database

I am considering replacing a MySQL database with a neo4j database. I am a complete beginner with neo4j and would like to know how to go about doing a batch insert of my current MySQL data into the neo4j database so i can experiment and begin to learn about neo4j.
the relational database consists of 4 tables: Person, Organism, Story, Links.
Links describes relationships between rows in the other 3 tables.
Links:
ID, FromTable, FromID, ToTable, ToID, LinkType
Person:
ID, property_2, property_1, etc ...
Organism:
ID, property_A, property_B, etc ....
Story:
ID, property_x, property_y
each ID field is an auto incrementing integer starting from 1 for each table
In case it is not obvious, a link between say person with ID 3 and a story with ID 42 would have a row in the Links table ID=autoincrement, FromTable=Person, FromID=3, ToTable=Story, ToID=42.
Even though I am using the terms 'from' and 'to' the actual links are not really 'directed' in practice.
I have looked at Michael Hunger's batch-import but that seems to only work with a single table of nodes and one table of relationships, whereas I am looking to import three different types of nodes and one list of relationships between them.
I have got neo4j up and running,
Any advice to get me started would be greatly appreciated.
I am not familiar with Java, though I do use Python and bash shell scripts.
After initial import, I will be using the RESTful interface with Javascript.
Based on advice in the git repo. Using Michael Hunger's batch-import it is possible to import multiple node types from the one .csv file.
To quote Michael:
Just put them all into one nodes file, you can have any attribute not
having a value in a certain row, it will then just be skipped.
So the general approach i used was:
combine all the nodes tables into a new table called nodes:
Create a new table nodes with an auto incrementing newID field and a type field. the type field will record what table the node data came from
Add all the possible columns names from the 3 node tables allowing nulls.
INSERT INTO nodes the values from Person, then Organism, then Story, in addition to setting the type field to person, organism, or story. Leave any unrelated fields blank.
in another new table rels add the newly created newID indexes to the Links table based on a sql JOIN:
INSERT INTO rels
SELECT
n1.newID AS fromNodeID,
n2.newID AS toNodeID,
L.LinkType,
L.ID
FROM
Links L
LEFT JOIN
nodes n1
ON
L.fromID = n1.ID
AND
L.fromType = n1.type
LEFT JOIN
nodes n2
ON
L.toID = n2.ID
AND
L.toType = n2.type;
Then export these two new tables nodes and rels as Tab seperated .csv files, and use them with batch-import:
$java -server -Xmx4G -jar target/batch-import-jar-with-dependencies.jar target/graph.db nodes.csv rels.csv
As you say that you are happy working with python and shell scripts, you may also want to have a look at the command line tools which come with py2neo, in particular geoff. This uses a flat file format I put together for holding graph data so in your instance, you would need to build a flat file from your source data and insert this into your graph database.
The file format and server plugin are documented here and the py2neo module for the client application is here.
If anything is missing from the docs or you want more information about this then feel free to drop me an email
Nigel

Resources