GhPython : struggling with accents

OK, got it : the name of my output isn’t “a”.

Anyway, I understand how scripting can give you super-powers, but I just managed to figure GH data trees, and now I realize that if I want to use databases, I have no choice but to also learn python…

Something like this (but then improved and better) would make you feel a bit happier?

accents.gh (4.7 KB)

For instance the component could parse the Query string to see how many fields are asked. Or even just directly the results to see how many there are. Figure out from the database schema what the names for these are and add those outputs magically for you.

Of course, multitable databases are going to be more tricky, but still is possible to do.

jSwan by @andheum is a nice example of automatic output population based on what the input (JSON) is.

So it is definitely possible to do something like jSwan, but then for SQLite (or other databases even, no doubt).

I suspect it would be a hit !

So now, I need to concatenate two indices of the tuples ; no luck so far :

I guess you meant

SQL2_RESULT = [i[0] + i[1] for i in c.fetchall()]

?

1 Like

Exactly !

Thanks

Any idea why I can’t intergrate a simple operation on the items I retrieve with my query ?
I just want to substract “1” because the item numbers in the database start at “1” whereas GH trees start at “0”.

Also, I do have some nulls, and I don’t want them to become an integer when I substract 1 .
I managed to do it with GH components, but I admit it’s not very elegant :

OK, I found the easiest solution : use the power of SQL :

1 Like

Awesome! Could you share the Python Code?

@nathanletwory
Even better : I can concatenate my data with SQLite instead of Python …
Note that the operator is “||” for SQLite instead of the usual “CONCAT” :

Good to see you make progress and learn new tricks - even if you don’t like it (:

He he… So many things to learn, and all those hungry mouths to feed.
Who knows, I might have taught you something about SQLite …

I think databases are underrated around here.

I mean… the idea of just asking (SQL request) for something instead of painstakingly scripting the crap out of a language to obtain the same result is quite appealing to me.

If I had a programming background like you, I’d probably see things differently.
But I am really more focused on the task to accomplish (extract, filter and mildly alter data and make things happen with it) than on the “How to” do it.

You did. I have to admit though that it has been about a decade since I last used SQLite regularly. Databases I have used a lot though - one of my earliest SQL and 3D experimentation was to save Blender data blocks directly to a MySQL database instead of to a .blend file. That way one could do collaboration in a less-than-realtime fashion. Further huge MySQL and PostgreSQL database I’ve worked with through a BOINC-based project (a render farm), and for p3d.in (which I helped found and wrote the first beta versions for).

I understand. Still, you need to be able to set up your SQL query correctly - which in its own way is a form of programming (: But having to deal with the peculiarities of whatever programming language you’re using that through can be distracting.

1 Like

Wow… you seem like the right guy to create a few SQLite-friendly GH components, similar to JSwan as you mentionned. :innocent:

A few ideas come to mind :
-The SQL request handler (the subject of this thread)
-A component for creating the SQlite database / adding records to an existing one
-A component for editing / deleting existing records

I feel that it has more possible use cases than the JSON thing, but I have to admit I know very little about that critter.