aspJSON icon indicating copy to clipboard operation
aspJSON copied to clipboard

Problem when adding Parse, Add and Loadrecordsets

Open dtrillo opened this issue 4 years ago • 3 comments

Hi. I use the library adding data using Parse function, but also with the Add and LoadRecordset. the property name doesn't work as expected. Here is hoy I solved it!

I have notice some problems, that I have solved by defining my own LoadRecordset method. ` ' Load properties from an ADO RecordSet object into an array

' @param rs as ADODB.RecordSet

public sub LoadRecordSet(byref rs) ' Change 3.8.2

	LoadRecordSet2 rs, true

end sub

public sub LoadRecordSet3(byref rs) ' Change 3.8.2

	LoadRecordSet2 rs, false

end sub

public sub LoadRecordSet4(byref rs, prop_name) ' Change 3.8.2

	dim old_i

	old_i = i_defaultPropertyName

	i_defaultPropertyName = prop_name
	LoadRecordSet2 rs, true
	i_defaultPropertyName = old_i
end sub
' Load properties from an ADO RecordSet object into an array
' @param rs as ADODB.RecordSet
public sub LoadRecordSet2(byref rs, lcaseall) ' Change 3.8.2
	dim arr, obj, field
	set arr = new JSONArray
	while not rs.eof
		set obj = new JSONobject
		for each field in rs.fields
			k = field.name: if lcaseall then k = lcase(k)
			obj.Add k, field.value
		next
		arr.Push obj
		rs.movenext
	wend
	set obj = nothing
	add i_defaultPropertyName, arr
end sub`

With this 4 functions, I can get the desire outcome. first of all, because I can assing a name to the recordset, not loosing the previous name.

I notice you have not add the feature of lowercase properties (here included).

dtrillo avatar Mar 09 '20 15:03 dtrillo

Hi @dtrillo,

That is cool, thanks!

You can create a PR to add that functionality. Just need to fork the repo, create the change and send the PR. It will get merged with your contribution to the repo.

Also, what about giving more clear names to the methods there? My suggestions would be:

  • rename LoadRecordSet2 to LoadRecordSetWithCase
  • remove the other ones and change places that call them to call the LoadRecordSetWithCase using the proper flags, because that seems to be more clear and we don't introduce methods to wrap a boolean.

What do you think?

rcdmk avatar Mar 09 '20 17:03 rcdmk

I don't use GitHub very ofter because I don't have it available except at home, and this is a feature of my work. I will try to make the PR in the next days.

dtrillo avatar Mar 10 '20 16:03 dtrillo

I have a possible fix for this in development (4b5fef0), if you still wanna try that out.

rcdmk avatar Oct 04 '22 04:10 rcdmk