Null parameter values in Npgsql 3.x - npgsql

My ORM does not know the type for a null NpgsqlParameter value at runtime. In Npgsql 2.x I could simply set
parameter.value = DBNull.Value
and this was all good. Now it seems I have to set a DbType too, but I don't know what the type's supposed to be, so I can't set it.
In 2.x it seems to be defaulting to String/text, but setting that explicitly in 3.x causes type exceptions.
What can I do, without having to modify all my SQL?
Is there a default DbType that will give the 2.x behaviour?

Can you try setting NpgsqlDbType to NpgsqlDbType.Unknown?

Related

Convert hstore column to a XPO class property Npgsql 3.2.7

We have upgraded Npgsql from 2.2.5 to 3.2.7.
We have a database column of type hstore.
In 2.2.5
this column used to be converted by a XPO valueconverter
from a string that came from the database
to a List < Tuple< object, object>> that we wanted in a XPO class.
Before 3.2.7 something has changed
and when we try to read this column,
we get an error stating that "an object should implement IConvertible".
But it does not state, which object should be IConvertible.
I presume that this is the target XPO property,
of type List< Tuple< object,object>>
We have tried to change the property to IConvertible but without effect.
Has anybody had similar problems with the hstore type and the 3.* upgrade?
I have no idea exactly what your application does (or how XPO works), but Npgsql 3.x returns PostgreSQL hstore as Dictionary<string,string>. It seems like your client code (XPO?) may be expecting the value returned by Npgsql to be IConvertible, which isn't the case anymore.
OK, I got it. The change of the type read from the database from string to Dictionary has caused errors in XPO that does not handle it properly. Just in case somebody else encounters this issue: One needs to subclass PostgreSqlConnectionProvider and override the ReformatReadVaue() method to omit Dictionary. Second thing is a proper value converter for the property. https://www.devexpress.com/Support/Center/Question/Details/T614674/problem-with-hstore-fields-after-upgrading-from-16-2-to-17-2
Thank you again for pointing me at the right direction.

Trigger Rule with Filefield 'when field has changed' in Drupal 7

I've got a set of different rules that check if various field types have been updated 'after updating existing content'. The problem is that each one works fine, except for the only filefield type which will not work. The condition used is a 'NOT Data comparison' on the field checking the 'node-unchanged' version against the new 'node' version. This works with every other type of field and actions appropriately (that I have used at least), just not the filefield type; the rule just fires regardless of changes or not on the filefield.
I also found this post about a very similar problem: https://www.drupal.org/node/1011014#comment-10040082
I think I have the makings of a workaround, but I just wanted to check this with some fellow developers first as my PHP isn't the best.
If I were to enable the PHP module then add a condition in rules that checks the 'source' attribute to see if a new file has been added... would this work? The code I have is:
if (isset($object->field_FILEFIELD_NAME[0]['source'])) { //Check for new files }
I believe that $object is the node passed on by rule function as argument.
Is this a good idea/best approach? Any ideas or workarounds would be great.
Yes, you can use PHP for filefield checks as it is more clear (but always less secure). Here are my suggestions:
Create a Rule component (of type "Condition set (AND)") instead of a rule to do this check.
Use a parameter with your rule component (of type Node) so you have the $node available.
Use php to do the checks. Get the file data from the filefield using $node.
Create a normal rule (eg with event Before Saving Content) where you will use this component as a condition among others.
As you said you need to check for differences not for empty values, right? So instead of using isset you need to see if there is a different fid (which normally changes when there is a different file). Other methods are available and if you want to see which data can change do a dpm() to the filefield using devel module.
In order to get the unchanged value of the filefield use the same component on you main Rule but with the $unchanged node as parameter.

CakePHP doens't support load models?

I use CakePHP 1.3.9 but I can't use other Models in a Controller.
I use $this->loadModel('ModelName); and $this->ModelName->find('all') - always empty.
The variable $uses also doesn't work.
Why is it not working for me?
I used i18n and must set $locale...
Do you mean the data set is empty? If the model is not loaded, you shouldn't be able to call $this->ModelName->find() as $this->ModelName would be null. Does it throw an error? Your usage is correct, as stated in the manual : http://book.cakephp.org/view/992/loadModel
You can also do
App::import('Model', 'ModelName');
$model = new Model();
But I'm guessing that your current resultset is returning empty rather than the model itself not being set.
Have you tried looking at what $this->ModelName actually contains? Do the following and post it here
pr($this->ModelName)
It's considered bad practice to put (un-associated) models in your $uses array.
Depending what you are trying to do, you may be able to make use of containable behaviour.
$this->User->Post->find('all');
If not, you should be able to use loadModel:
$this->loadModel('Article');
$recentArticles = $this->Article->find('all', array('limit' => 5));
To quote Cake:
The loadModel function comes handy when you need to use a model which is not the controller's default model or its associated model.
JohnP and Ross are correct. Controller::loadModel() is clearly working and not your problem if pr($this->ModelName) is working for you.
As they mentioned, you're probably having trouble because the data simply isn't in the database. Or maybe there's something wrong with your query. Have you tried checking the query that's produced by CakePHP and trying to query the database directly through the MySQL command line (assuming you're using MySQL)?
Or is there any chance you've overloaded the Model::find() method?

Using a Guid Version column in NHibernate

We are working with a legacy database that uses SQL server uniqueidentifier columns for concurrency hence we need to use a Guid as a version column. Any idea how we could achieve this in NHibernate?
We're currently defining our mapping using Fluent NHibernate as a Guid typed property called ConcurrencyId using this snippet
Version(x => x.ConcurrencyId)
This results in the following error when creating a session
System.InvalidCastException : Unable to cast object of type 'NHibernate.Type.GuidType' to type 'NHibernate.Type.IVersionType'.
Any ideas on how this could be done, fluently or otherwise would be appreciated. We're happy to hack the source if it can be made to work.
You could try implementing a custom type implementing NHibernate.UserTypes.IUserVersionType. (I think this suggestion may pertain to a newer version of NHibernate than you are using.)
Check this...
http://ayende.com/Blog/archive/2009/04/15/nhibernate-mapping-concurrency.aspx
and the docs for the version property
http://www.nhforge.org/doc/nh/en/index.html#mapping-declaration-version
Looks like you can't use a Guid for this. Maybe just map it as a property and handle the version checks yourself.

CakePHP based project is throwing error saying " return value of new by Reference is Deprecated"

I have upgraded my Xampp to newer version(1.7.2).But right now when I run my project(done in CakePHP) it is throwing bug saying
Deprecated: Assigning the return value of new by reference is deprecated in
C:\xampp\htdocs\ebayn\cake\libs\debugger.php on line 99
Deprecated: Assigning the return value of new by reference is deprecated in
C:\xampp\htdocs\ebayn\cake\libs\debugger.php on line 108
Deprecated: Assigning the return value of new by reference is deprecated in
C:\xampp\htdocs\ebayn\cake\libs\file.php on line 96
Deprecated: Assigning the return value of new by reference is deprecated in
C:\xampp\htdocs\ebayn\cake\libs\cache\file.php on line 89
Can anyone help me how can I rectify this stuff....???
Thanks In Advance
You need to patch the cake/libs/configure.php and find the line "error_reporting(E_ALL);" replace that line with the following:
error_reporting(E_ALL & ~E_DEPRECATED);
You may need to change this in your app/webroot/index.php and respectively test.php, too.
There is currently no better way than to touch the core.
You don't mention your CakePHP version, but if you use PHP 5.3 (which is part of Xampp 1.7.2) then you have to use CakePHP 1.3.x.x.
You haven't included any code, but it looks like you may be attempting to assign a variable by reference - probably an instance of an object. In PHP 5+, that's the default, as I recall. In 5.3, they may have officially deprecated the practice.
If your app has to work with PHP 4, you may want to look at your error_reporting setting. If E_STRICT is set, turn it off. I don't recall which settings effect which types of errors, but that particular value will probably be instructive if I were to guess.
I found I needed to roll PHP 5.3 back to php 5.2 in MAMP in order to run Cake 1.2.
Need to get a local copy of an old client site throwing useful errors, instead of just an Internal Server Error.
Progress...

Resources