Skip to content
This repository has been archived by the owner on Mar 14, 2020. It is now read-only.

Question regarding happypanda.db reading on SQLStudio #190

Open
UnlimitedArk opened this issue Feb 10, 2018 · 2 comments
Open

Question regarding happypanda.db reading on SQLStudio #190

UnlimitedArk opened this issue Feb 10, 2018 · 2 comments

Comments

@UnlimitedArk
Copy link

Hi, i'd like to pose a question regarding the happypanda.db, specifically when reading it with sqlite studio ;
i've also tried asking this question elsewhere (like on hydrus, where there's a similar situation), but i can't seem to get an answer on if this operation is even possible.

Basically, in the db, i'm looking at these three tables : namespaces, tags and tags_mappings.
Namespaces has columns for IDs and text values, for example id 4 : artist ; tags table is basically the same, but obviouslly for the subtags, for example id 300:hisasi.
Tags_mappings has 3 columns for IDs (mapping, namespace, tag) ; continuing the example, pairing 350 could be for namespace 4 and tag 300, thus artist:hisasi.
The problem is that this table doesn't list the text values, only the ids, meaning that in order to find what each mapping represented, i'd have to manually search in the previous 2 tables what namespace_id 4 and tag_id 300 stood for.

What i'm asking is : is it possible to add, to the tags_mappings table, the text values that are in the previous tables? Either by adding 2 new columns and fill them with the right values or outright swapping the ids in place for the text.
Unfortunately it's not even a matter of simply copying and pasting all the rows, since there are repeated ids as results of pairings ;
what i need is, for every row that has namespace_id 4, the new column should have "artist" (or instead, swap out the "4" for "artist").

Still, i'm trying to understand if such an operation is even posssible, i've been suggestd the INNER JOIN command, but i can't seem to make it work as the text values are not listed in the query result, and there was no further elaboration.

As to why i need to do this, again it's not specifically related to happypanda (altho it could be useful in the series_tags_map table to see all the tags that each gallery had), it's more of a hydrus problem in a situation where i could only read the database and needed to see some tag pairings to recover lost stuff.
I thought of asking the same thing here too since it could apply just as much.

Thanks for the help regardless.

@twiddli
Copy link
Owner

twiddli commented Feb 10, 2018

Hello,
It was a bit of a confusing read but If i understand correctly then, yes, I think it should be possible.
I'm not an expert on SQL so I can't give you a definitive answer, however, I can tell you where I'd be looking.
Look into SQL Triggers http://www.sqlitetutorial.net/sqlite-trigger/.
I'm actually not sure of the limitations of SQL triggers but it might be possible to create two new columns in tags_mappings as you suggested, and then create a trigger to insert or update the text from from tags and namespaces into those two columns. I think this is what you want?

As for HP specifically, you could just periodically export the database to a HPDB file in the settings. This is just a JSON file containing all the gallery metadata in an easy to read manner. No need to fiddle with SQL.

@UnlimitedArk
Copy link
Author

Thanks for the response, i'll look into triggers to see if it's the answer i seek.
Sorry for the confusing explanation, it's a bit hard trying to explain that i need the new columns to be filled with the right text values correlated to the IDs in those rows.

Dunno if it makes it a bit easier to understand, or even harder, but here's an example of what i'm trying to accomplish.
example 2

In this example, most of the rows contain 22 as namespace id, thus the new column "namespace" takes the data from the namespaces table (where the column shows that 22=artist) and writes "artist" as a result on every row until namespace_id 3 ;
same with the new "tag" table, every id gets the correct text value and is an easier read than having just IDs withouth knowing what they stand for and having to search manually one by one.

Thanks for the help anyway, i'm thankful that happypanda doesn't need this kind of operations to read the contents of its database.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants