Inconsistent date types from MySQL Database in Perspective?

I’m having a very difficult time figuring this out. In perspective, we have a function that after insert/update, we check that it worked. We do this based on type and values. With dates I like to use the native that we get from date columns in MySQL and compare them to the objects I get from date components.

I am getting an error from my function anytime I try to update a date column via perspective now though in my chrome console about mismatched types between the db and what I fed it -

So in my select statement that’s running to check if the update worked, SELECT lastStartDateSelected FROM listusers WHERE idx = 3047. Here’s the short script I use to get the value/type for my check -

selectQuery = "SELECT %s FROM %s WHERE idx = %i"%(columnNames, tableName, idx)
	system.perspective.print("SELECT QUERY: " + str(selectQuery))
	results = system.dataset.toPyDataSet(system.db.runQuery(selectQuery))
	badResult = False
	for key in dictionary.keys():
		databaseValue = results[0][str(key)]
		dictionaryValue = dictionary[key]
		system.perspective.print("db Value: " + str(databaseValue))
		system.perspective.print("db Type: " + str(type(databaseValue)))
		system.perspective.print("dict value: " + str(dictionaryValue))
		system.perspective.print("dict type: " + str(type(dictionaryValue)))

Now here is the odd thing, running the very same select statement in the scripting console and doing type on it gives me a which is what I expect, but for some reason, perspective calling this function and running the same exact query returns a java.sql.timestamp which ruins my comparisons. Any idea why this is and if it can be changed?

java.sql.Timestamp is a subclass of java.util.Date - it should work the same for comparison purposes:

If you specifically need a date, you could convert it back pretty easily; check if isinstance(java.sql.Timestamp), then convert it via

1 Like

OK this does work. I know with Perspective all the scripts run on the gateway - is that what causes it to be a different type? Some different logic in the gateway with handling a date column vs running the same query via a client? This really threw me for a loop for a bit lol.

Yeah, we’re probably serializing to a Date directly before sending the results down to the client, but on the gateway you’re getting them directly.

1 Like