protected function cast_row(&$row) { assert('is_assoc_array($row)'); foreach ($row as $name => $value) { /* Don't cast null values */ if (is_null($value)) { continue; } switch ($this->field_types[$name]) { case 'int2': case 'int4': case 'int8': $value = (int) $value; break; case 'float4': case 'float8': case 'numeric': case 'money': $value = (double) $value; break; case 'varchar': case 'bpchar': $value = (string) $value; break; case 'bool': $value = $value === 't'; break; case 'timestamp': case 'date': case 'time': case 'datetime': $value = AnewtDateTime::parse_string($value); break; case 'inet': /* FIXME: What to do with these? */ /* FIXME: What to do with these? */ default: /* No conversion, leave as string */ break; } $row[$name] = $value; } }
protected function cast_row(&$row) { assert('is_assoc_array($row)'); foreach ($row as $name => $value) { $type = $this->field_types[$name]; /* Don't cast null values */ if (is_null($value)) { continue; } switch ($type) { case 'int': $value = (int) $value; break; case 'real': $value = (double) $value; break; case 'string': case 'blob': $value = (string) $value; break; case 'date': case 'datetime': case 'time': case 'timestamp': $value = AnewtDateTime::parse_string($value); break; default: /* No conversion, leave as string */ break; } $row[$name] = $value; } }
/** * Parses a date into a AnewtDateTimeAtom instance. The function also accepts * AnewtDateTimeAtom instances. In that case the supplied instance is returned. * If parsing fails, null is returned. * * Note that in many cases you should just call one of the more specific * parsing methods instead. * * \param $date * An int/string/AnewtDateTimeAtom which will be parsed. * * \return * A newly created AnewtDateTimeAtom instance or null if parsing failed. * * \see AnewtDateTime::parse_timestamp * \see AnewtDateTime::parse_string * \see AnewtDateTime::parse_ymd */ static function parse($date) { /* Integers are treated as unix timestamps */ if (is_int($date)) { return AnewtDateTime::parse_timestamp($date); } /* Try to parse strings */ if (is_string($date)) { return AnewtDateTime::parse_string($date); } /* Double parsing should be harmless */ if ($date instanceof AnewtDateTimeAtom) { return $date; } /* Too bad, better luck next time... */ return null; }
<?php require_once dirname(__FILE__) . '/../anewt.lib.php'; anewt_include('calendar'); $calendar = new AnewtCalendar(); $event = new AnewtCalendarEvent('Title'); $event->date_start = AnewtDateTime::parse_string('2009-01-01 12:00'); $event->date_end = AnewtDateTime::parse_string('2009-01-01 14:00'); $event->summary = 'This is the summary'; $event->location = 'This is the location'; $event->url = 'http://example.org/foo'; $event->uid = 'abc1234567890'; $calendar->add_event($event); $event = new AnewtCalendarEvent('Another event', AnewtDateTime::now()); $event->summary = "This is a multiline\nsummary"; $event->summary = "This is a multiline\ndescription"; $calendar->add_event($event); $calendar->flush();
protected function cast_row(&$row) { assert('is_assoc_array($row)'); foreach ($row as $name => $value) { $type = $this->field_types[$name]; /* Don't cast null values */ if (is_null($value)) { continue; } switch ($type) { case MYSQLI_TYPE_DECIMAL: case MYSQLI_TYPE_NEWDECIMAL: case MYSQLI_TYPE_BIT: case MYSQLI_TYPE_TINY: case MYSQLI_TYPE_SHORT: case MYSQLI_TYPE_LONG: case MYSQLI_TYPE_INT24: case MYSQLI_TYPE_YEAR: $value = (int) $value; break; case MYSQLI_TYPE_LONGLONG: /* Only cast BIGINTs on 64 bit platforms that can actually hold the values in an integer data type. */ if (PHP_INT_SIZE >= 8) { $value = (int) $value; } break; case MYSQLI_TYPE_FLOAT: case MYSQLI_TYPE_DOUBLE: $value = (double) $value; break; case MYSQLI_TYPE_TINY_BLOB: case MYSQLI_TYPE_MEDIUM_BLOB: case MYSQLI_TYPE_LONG_BLOB: case MYSQLI_TYPE_BLOB: case MYSQLI_TYPE_VAR_STRING: case MYSQLI_TYPE_STRING: case MYSQLI_TYPE_CHAR: $value = (string) $value; break; case MYSQLI_TYPE_TIMESTAMP: case MYSQLI_TYPE_DATE: case MYSQLI_TYPE_TIME: case MYSQLI_TYPE_DATETIME: case MYSQLI_TYPE_NEWDATE: $value = AnewtDateTime::parse_string($value); break; case MYSQLI_TYPE_ENUM: case MYSQLI_TYPE_INTERVAL: case MYSQLI_TYPE_ENUM: case MYSQLI_TYPE_SET: case MYSQLI_TYPE_GEOMETRY: /* XXX: Fall-through: what should be done with these? */ /* XXX: Fall-through: what should be done with these? */ default: /* No conversion, leave as string */ break; } $row[$name] = $value; } }
protected function cast_row(&$row) { assert('is_assoc_array($row)'); foreach ($row as $name => $value) { $type = $this->field_types[$name]; /* Don't cast null values */ if (is_null($value)) { continue; } switch ($type) { case 'int': /* Issue: this doesn't work for BIGINTs on 32 bits * platforms, but there is no way to find out when this * happens (both have a 'int' field type). :( The solution * is to use MySQLi instead. */ $value = (int) $value; break; case 'real': $value = (double) $value; break; case 'string': case 'blob': $value = (string) $value; break; case 'date': case 'datetime': case 'time': case 'timestamp': $value = AnewtDateTime::parse_string($value); break; default: /* No conversion, leave as string */ break; } $row[$name] = $value; } }