DASSL / ClassDB

An open-source system to let students experiment with relational data
https://dassl.github.io/ClassDB/
Other
8 stars 2 forks source link

Remove managerName, use %s, add foldpgID, implement helperFunctions #92

Closed afig closed 7 years ago

afig commented 7 years ago

This pull request fixes the inconsistencies we had with case and quote sensitivity with role and schema names.

I am not certain about foldPgID as the name of the function, but it might suffice for now. One oddity with the function is that the input parameter is VARCHAR(65), but it returns a VARCHAR(63). This is to allow for the maximum length of an identifier (63), and surrounding quotes. The surrounding quotes would be removed before returning the value. There could be a bit more safety with the function so that it always returns a maximum of 63 characters. There is no check that an input that is 64 or 65 characters long actually is quoted. Another issue is that Postgres does not check or even truncate a parameter value that exceeds the size of the VARCHAR(65), nor does it check that the function returns a value this is 63 characters or less.

There should be no issues with merging at this point. Future code may require the use of foldPgID, and should follow the new convention of using %s.

Fixes #85 and #86.

smurthys commented 7 years ago

Nice idea to have a function foldPgID.

I am wondering if we could take advantage of this change to replace the many instances of the query SELECT * FROM pg_catalog.pg_roles WHERE rolname = classdb.foldPgID($1) with a call to classdb.isRoleDefined. Further, could some of the helper functions call foldPgID so the callers don't have to explicitly call foldPgID everywhere?

afig commented 7 years ago

That would be a great idea. I will add those changes onto this branch since similar changes are being made anyways.

It would be possible to have some helper functions use foldPgID. Of course the definition of foldPgIDhas to come first if that is the case.

I forgot to mention this above, but we also need to solve the circular dependency between addHelperFunctions and prepareClassDB. Specifically, functions in prepareClassDB need the functions located in addHelperFunctions, however, addHelperFunctions needs the classdb schema, which is created in prepareClassDB. I do not recall if we decided how to best solve this situation.

smurthys commented 7 years ago

I have thought about many alternatives to the issue of creating the classdb schema. Although not elegant, the quickest fix is to move the code to create classdb schema to addHelperFunctions.sql.

I believe I have a better alternative, but I propose proceeding with the aforementioned quick fix (after analyzing it of course). I will send out a mail with the details of the alternative.

afig commented 7 years ago

Yes there would be an issue with values provided by the Postgres, since it does not quote values that should be case-sensitive. This can be avoided by only using foldPgID with values provided by a user.

wildtayne commented 7 years ago

Thanks for the clarification. I also didn't consider the fact that pgFoldID() returns string data, so it wouldn't work in that context anyway. It's definitely a useful function.