Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADODB_DataDict._GenFields: Unconditional remove of nullability and default on blobs #292

Closed
obmsch opened this issue Nov 12, 2016 · 2 comments
Milestone

Comments

@obmsch
Copy link
Contributor

obmsch commented Nov 12, 2016

In 'adodb-datadict' inside _GenFields:

line 729
if ($ty == 'X' || $ty == 'X2' || $ty == 'B') $fnotnull = false; // some blob types do not accept nulls [cf #291]

line 733-734
//some databases do not allow blobs to have defaults
if ($ty == 'X') $fdefault = false;

Thats completely ignoring the capabilites of any db to honor some dbs not implementing that feature. I am looking for a better approach(My knowledge of php and its inner workings is really limited. So this is more conceptional than a real implementation).

Add members (for capabilities) to the base class ADODB_DataDict like
$hasNullableBlobs = false;
$hasDefaultOnBlobs = false;

Change the code above to:
if (!$this->hasNullableBlobs && ($ty == 'X' || $ty == 'X2' || $ty == 'B')) $fnotnull = ...
and
if (!$this->hasDefaultOnBlobs && $ty == 'X') $fdefault = false;

Thats a noop in behaviour of ADOdb.

But lets say a db supports NULL in blobs, setting $hasNullableBlobs = true; in its datadict should do the trick.

@obmsch
Copy link
Contributor Author

obmsch commented Nov 29, 2016

Missed an outstanding pull request pr #118, adressing this issue.

Reconsidering my first thougts and the approach taken in the pull request, I would now recommend to handle this in a more general way in the generic datadict. There might be other field types beside blobs with restrictions too.

And if we agree on:

Any given schema should be me mapped as precisely as possible to the underlying db.

then

Either we drop those lines completely and let it to the dbs datadict to handle this, implementing its own _GenFields or take care of it in Add/AlterColumnSQL (caveat: to preserve current behaviour all dbs datadicts have to be adjusted, and at least me don't know what all the supported dbs would require then).

or

a) Extend the generic datadict with something like:

  HasNull($t) {
    return true;
  }
  HasDefault($t) {
    return true;
  }

b) Alter the corresponding lines:

if (!this->HasNull($ty)) {
   $fnotnull = false;
}

if (!this->HasDefault($ty)) {
   $fdefault = false;
}

c) To preserve current behaviour (and put it to the db to handle) extend all dbs datadicts with:

HasNull($t) {
  case 'X':
  case 'X2':
  case 'B' : return false;
  default: return true;
}
  
HasDefault($t) {
  case 'X' : return false;
  default: return true;
}

d) Adjust (c) for the known ones (datadict_?) in the first place [1]:

mysql (from pr #118)

  HasNull($t) {
    return true;
  }

postgres (from pr #118)

  HasNull($t) {
    return true;
  }
  HasDefault($t) {
    return true;
  }

mssql (me)

  HasNull($t) {
    return true;
  }
  HasDefault($t) {
    return true;
  }

If this sounds reasonable to the devs and we could agree on d)+[1] I would volunteer a pull request on this. But given the hassle I have had with the last one (git with me and my dev box 👎 ), only if the path we want to go is set.

[1] Correct/Add others.

@dregad
Copy link
Member

dregad commented Nov 30, 2016

@obmsch thank you for your follow-up and proposal to volunteer. Due to my current workload I don't cant look at this into details ATM, will do so as soon as I can (no promises on when).

As a side note, if you need any help with Git, feel free to contact me on Gitter at any time though.

mnewnham added a commit that referenced this issue Aug 26, 2018
ADOdb automatically disallows setting of NOT NULL or DEFAULT values on blob type fields. This was due to historic limitations on data types that no longer exists.
This commit takes the work done in pr #118  by @obmsch  and adds the driver  for SQLite
@mnewnham mnewnham closed this as completed Jan 4, 2019
obmsch added a commit to obmsch/ADOdb that referenced this issue Jan 13, 2019
Add 'XL' to the blob checks in _GenFields.
@obmsch obmsch mentioned this issue Jan 13, 2019
@dregad dregad added this to the v5.21 milestone Dec 29, 2019
dregad pushed a commit that referenced this issue Dec 29, 2019
ADOdb automatically disallows setting of NOT NULL or DEFAULT values on
blob type fields. This was due to historic limitations on data types
that no longer exists.

This commit takes the work done in PR #118  by @obmsch  and adds the
driver for SQLite.

Fixes #292
dregad pushed a commit that referenced this issue Dec 29, 2019
dregad pushed a commit that referenced this issue Dec 29, 2019
Add 'XL' to the blob checks in _GenFields.

See #292
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants