I'm having trouble with a computed field that I want to be a text value.

Later I plan to add some actual logic to set the value, but for now, all I have is

Required: not checked
Multiple values: not checked

Computed Code: $node_field[0]['value'] = "RESERVED";

Display this field: checked.

Display Format: $display = "Status: " . $node_field_item['value'];

Store using the database settings below: checked

Data Type: text (also tried varchar)
Data Length:
Default Value:
Not NULL: unchecked
Sortable : checked

All I see is:
Status:

Thanks

Comments

skor’s picture

Also tried

Data Length: 64

with both varchar and text.

wrunt’s picture

Hi Skor,

Have you tried editing and saving the node you're testing with? The value will only be computed on save. For something short like that I'd probably go for varchar with data length 64. The data length is needed.

skor’s picture

thanks for the quick response.

Good thought, I hadn't been re-saving, but even when I made some changes and saved, it didn't show up.

skor’s picture

looking at phpmyadmin, there doesn't appear to be a row for this field in the database

fyi, using Drupal 4.7.3, MySQL 4.1.21
// $Id: computed_field.module,v 1.1.2.11 2006/09/15 00:39:28 wrunt Exp $
// $Id: content.module,v 1.56.2.20 2006/09/19 00:41:42 JonBob Exp $

skor’s picture

Category: support » bug

Ok, if I create a computed field, and make it an int, I get a row in the database. And then, if I go set the type to varchar, the type in the database stays int.

Not sure yet if the problem is in computed field, or CCK, but I'm pretty sure it's a bug.

skor’s picture

and at some point, shouldn't I have gotten this warning for a blank data length?

    116         if (!isset($field['data_length'])) {
    117           form_set_error($field['data_type'], t('To store this field in the database, please specify the data length.

Ok, I'm tired and I'm mixing issues. Here's what I've got so far:

  1. Normal Bug: Computed text fields apparently don't get added to the database. can anyone verify?
  2. Minor Bug: Apparently cannot change data type (at least from int to varchar) once the field is created. I base this on what phpMyAdmin says the datatype is. Oddly, when I edit the field, it shows varchar. I don't actually see this as a neccesary feature, as I could always delete and re-create the field if I wanted to change the type.Can anyone verify?
  3. feature request: field settings not getting validated. Data Length is a required field, but I created a field with a blank data length. Maybe it never got validated because it never got created in the database
wrunt’s picture

I'll take a look at this tonight. I've been meaning to add validation to that part of the form, and since it's been a problem for at least one person I guess I'd better do it.

As for your main problem, I'm not sure what's going on. The database_columns return of one of the cck hooks should be used by cck to change the data type, so if you change it then cck should change it. Maybe the bug has been introduced in the latest cck release, which I haven't tested with. I'll see if I can reproduce the bug tonight as well.

wrunt’s picture

I've had a play on a fresh install with the same version of cck and computed field that you used. I didn't get any errors.

I created a new content type called 'test computed field'. I gave the content type one computed field. I gave the computed field the same settings as you did, using varchar 64. I created a new node using my new content type and 'Status: RESERVED' showed up as expected.

Next I tried changing the field's data type to int, and checked that the data type of the computed field in the node_content_test_computed_field table had changed. I changed it back to varchar and again the data type changed.

What database are you using? Maybe the permissions aren't set up right? If you don't have the ALTER permission then that may cause the error you're getting.

wrunt’s picture

I've fixed the validation of data length. You shouldn't be able to submit an empty data length if storing the field in the database. This shouldn't actually have caused a problem before, because the code dealt with an empty data length by setting it to a default of 32.

skor’s picture

I'm using Mysql 4.1.21 with Drupal 4.7.3 and the userid for the database has all privileges that Cpanel offers: SELECT, CREATE, INSERT, ALTER, UPDATE, DROP, DELETE, LOCK TABLES, INDEX, REFERENCES, CREATE TEMPORARY TABLES.

I'll try it on a fresh 4.7.3 install tomorrow, in case there's something corrupted with this one.

skor’s picture

Status: Active » Closed (fixed)

OK, I tried it on my production site (finally upgraded my events from flexinode to CCK).

Everything worked just fine. Hope I didn't waste too much of your time on this.

I'd been playing around on the development site for quite a while since I last re-synced to the primary database. I'll re-sync it, and try it out again. Hopefully it will go away.

Thanks again.

wrunt’s picture

Cool, I'm glad you worked it out. I got drupal working on my mac and fixed a few bugs, so no time wasted here.