~mathiaz/ubuntu/lucid/mysql-dfsg-5.1/zap-bug-552053

« back to all changes in this revision

Viewing changes to sql/item.cc

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2009-06-25 12:55:45 UTC
  • mfrom: (1.1.2 upstream) (0.1.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20090625125545-m8ogs96zzsri74xe
Tags: 5.1.34-1ubuntu1
* Merge from debian experimental (and 5.0 from main), remaining changes:
  - debian/mysql-server-5.1.config:
    + ask for MySQL root password at priority high instead of medium so
      that the password prompt is seen on a default install. (LP: #319843)
    + don't ask for root password when upgrading from a 5.0 install.
  - debian/control:
    + Make libmysqlclient16-dev a transitional package depending on
      libmysqlclient-dev.
    + Make libmysqlclient-dev conflict with libmysqlclient15-dev.
    + Don't build mysql-server, mysql-client, mysql-common and
      libmysqlclient15-dev binary packages since they're still provided
      by mysql-dfsg-5.0.
    + Make mysql-{client,server}-5.1 packages conflict and
      replace mysql-{client,server}-5.0, but not provide
      mysql-{client,server}.
    + Depend on a specific version of mysql-common rather than the src
      version of mysql-dfsg-5.1 since mysql-common is currently part of
      mysql-dfsg-5.0.
    + Lower mailx from a Recommends to a Suggests to avoid pulling in
      a full MTA on all installs of mysql-server. (LP: #259477)
  - debian/rules:
    + added -fno-strict-aliasing to CFLAGS to get around mysql testsuite
      build failures.
    + install mysql-test and sql-bench to /usr/share/mysql/ rather than
      /usr/.
  - debian/additions/debian-start.inc.sh: support ANSI mode (LP: #310211)
  - Add AppArmor profile:
    - debian/apparmor-profile: apparmor profile.
    - debian/rules, debian/mysql-server-5.0.files: install apparmor profile.
    - debian/mysql-server-5.0.dirs: add etc/apparmor.d/force-complain
    - debian/mysql-server-5.0.postrm: remove symlink in force-complain/ on
      purge.
    - debian/mysql-server-5.1.README.Debian: add apparmor documentation.
    - debian/additions/my.cnf: Add warning about apparmor. (LP: #201799)
    - debian/mysql-server-5.1.postinst: reload apparmor profiles.
  - debian/additions/my.cnf: remove language option. Error message files are
    located in a different directory in MySQL 5.0. Setting the language
    option to use /usr/share/mysql/english breaks 5.0. Both 5.0 and 5.1
    use a default value that works. (LP: #316974)
  - debian/mysql-server-5.1.mysql.init:
    + Clearly indicate that we do not support running multiple instances
      of mysqld by duplicating the init script.
      (closes: #314785, #324834, #435165, #444216)
    + Properly parameterize all existing references to the mysql config
      file (/etc/mysql/my.cnf).
  - debian/mysql-server-5.0.postinst: Clear out the second password
    when setting up mysql. (LP: #344816)
  - mysql-server-core-5.1 package for files needed by Akonadi:
    + debian/control: create mysql-server-core-5.1 package.
    + debian/mysql-server-core-5.1.files, debian/mysql-server-5.1.files:
      move core mysqld files to mysql-server-core-5.1 package.
  - Don't package sql-bench and mysql-test file.
* Dropped changes:
  - debian/patches/92_ssl_test_cert.dpatch: certificate expiration in
    test suite (LP: #323755). Included upstream.
* Dropped from 5.0:
  - apparmor profile:
    - debian/control: Recommends apparmor >= 2.1+1075-0ubuntu6. All version
      of apparmor-profile (>hardy) are higher than this version.
    - debian/mysql-server-5.0.preinst: create symlink for force-complain/
      on pre-feisty upgrades, upgrades where apparmor-profiles profile is
      unchanged (ie non-enforcing) and upgrades where the profile
      doesn't exist. Support for pre-hardy upgrades is no longer needed.
* debian/mysql-server-5.1.postinst: fix debian-sys-maint user creation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
327
327
{
328
328
  MYSQL_TIME ltime;
329
329
  if (get_time(&ltime))
330
 
    return set_field_to_null(field);
 
330
    return set_field_to_null_with_conversions(field, 0);
331
331
  field->set_notnull();
332
332
  return field->store_time(&ltime, MYSQL_TIMESTAMP_TIME);
333
333
}
337
337
{
338
338
  MYSQL_TIME ltime;
339
339
  if (get_date(&ltime, TIME_FUZZY_DATE))
340
 
    return set_field_to_null(field);
 
340
    return set_field_to_null_with_conversions(field, 0);
341
341
  field->set_notnull();
342
342
  return field->store_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
343
343
}
1274
1274
    valid_args guarantees value_item->basic_const_item(); if type is
1275
1275
    FUNC_ITEM, then we have a fudged item_func_neg() on our hands
1276
1276
    and return the underlying type.
 
1277
    For Item_func_set_collation()
 
1278
    e.g. NAME_CONST('name', 'value' COLLATE collation) we return its
 
1279
    'value' argument type. 
1277
1280
  */
1278
 
  return valid_args ?
1279
 
             (((value_item->type() == FUNC_ITEM) &&
1280
 
               (((Item_func *) value_item)->functype() == Item_func::NEG_FUNC)) ?
1281
 
             ((Item_func *) value_item)->key_item()->type() :
1282
 
             value_item->type()) :
1283
 
           NULL_ITEM;
 
1281
  if (!valid_args)
 
1282
    return NULL_ITEM;
 
1283
  Item::Type value_type= value_item->type();
 
1284
  if (value_type == FUNC_ITEM)
 
1285
  {
 
1286
    /* 
 
1287
      The second argument of NAME_CONST('name', 'value') must be 
 
1288
      a simple constant item or a NEG_FUNC/COLLATE_FUNC.
 
1289
    */
 
1290
    DBUG_ASSERT(((Item_func *) value_item)->functype() == 
 
1291
                Item_func::NEG_FUNC ||
 
1292
                ((Item_func *) value_item)->functype() == 
 
1293
                Item_func::COLLATE_FUNC);
 
1294
    return ((Item_func *) value_item)->key_item()->type();            
 
1295
  }
 
1296
  return value_type;
1284
1297
}
1285
1298
 
1286
1299
 
1518
1531
    else
1519
1532
    {
1520
1533
      // Cannot apply conversion
1521
 
      set(0, DERIVATION_NONE, 0);
 
1534
      set(&my_charset_bin, DERIVATION_NONE,
 
1535
          (dt.repertoire|repertoire));
1522
1536
      return 1;
1523
1537
    }
1524
1538
  }
1601
1615
{
1602
1616
  uint i;
1603
1617
  Item **arg;
 
1618
  bool unknown_cs= 0;
 
1619
 
1604
1620
  c.set(av[0]->collation);
1605
1621
  for (i= 1, arg= &av[item_sep]; i < count; i++, arg++)
1606
1622
  {
1607
1623
    if (c.aggregate((*arg)->collation, flags))
1608
1624
    {
 
1625
      if (c.derivation == DERIVATION_NONE &&
 
1626
          c.collation == &my_charset_bin)
 
1627
      {
 
1628
        unknown_cs= 1;
 
1629
        continue;
 
1630
      }
1609
1631
      my_coll_agg_error(av, count, fname, item_sep);
1610
1632
      return TRUE;
1611
1633
    }
1612
1634
  }
 
1635
 
 
1636
  if (unknown_cs &&
 
1637
      c.derivation != DERIVATION_EXPLICIT)
 
1638
  {
 
1639
    my_coll_agg_error(av, count, fname, item_sep);
 
1640
    return TRUE;
 
1641
  }
 
1642
 
1613
1643
  if ((flags & MY_COLL_DISALLOW_NONE) &&
1614
1644
      c.derivation == DERIVATION_NONE)
1615
1645
  {
1628
1658
}
1629
1659
 
1630
1660
 
1631
 
/**
1632
 
  Collect arguments' character sets together.
1633
 
 
1634
 
  We allow to apply automatic character set conversion in some cases.
1635
 
  The conditions when conversion is possible are:
1636
 
  - arguments A and B have different charsets
1637
 
  - A wins according to coercibility rules
1638
 
    (i.e. a column is stronger than a string constant,
1639
 
     an explicit COLLATE clause is stronger than a column)
1640
 
  - character set of A is either superset for character set of B,
1641
 
    or B is a string constant which can be converted into the
1642
 
    character set of A without data loss.
1643
 
    
1644
 
  If all of the above is true, then it's possible to convert
1645
 
  B into the character set of A, and then compare according
1646
 
  to the collation of A.
1647
 
  
1648
 
  For functions with more than two arguments:
1649
 
  @code
1650
 
    collect(A,B,C) ::= collect(collect(A,B),C)
1651
 
  @endcode
1652
 
  Since this function calls THD::change_item_tree() on the passed Item **
1653
 
  pointers, it is necessary to pass the original Item **'s, not copies.
1654
 
  Otherwise their values will not be properly restored (see BUG#20769).
1655
 
  If the items are not consecutive (eg. args[2] and args[5]), use the
1656
 
  item_sep argument, ie.
1657
 
  @code
1658
 
    agg_item_charsets(coll, fname, &args[2], 2, flags, 3)
1659
 
  @endcode
1660
 
*/
1661
 
 
1662
 
bool agg_item_charsets(DTCollation &coll, const char *fname,
1663
 
                       Item **args, uint nargs, uint flags, int item_sep)
 
1661
bool agg_item_set_converter(DTCollation &coll, const char *fname,
 
1662
                            Item **args, uint nargs, uint flags, int item_sep)
1664
1663
{
1665
1664
  Item **arg, *safe_args[2];
1666
1665
 
1667
 
  LINT_INIT(safe_args[0]);
1668
 
  LINT_INIT(safe_args[1]);
1669
 
 
1670
 
  if (agg_item_collations(coll, fname, args, nargs, flags, item_sep))
1671
 
    return TRUE;
1672
 
 
1673
1666
  /*
1674
1667
    For better error reporting: save the first and the second argument.
1675
1668
    We need this only if the the number of args is 3 or 2:
1749
1742
}
1750
1743
 
1751
1744
 
 
1745
/* 
 
1746
  Collect arguments' character sets together.
 
1747
  We allow to apply automatic character set conversion in some cases.
 
1748
  The conditions when conversion is possible are:
 
1749
  - arguments A and B have different charsets
 
1750
  - A wins according to coercibility rules
 
1751
    (i.e. a column is stronger than a string constant,
 
1752
     an explicit COLLATE clause is stronger than a column)
 
1753
  - character set of A is either superset for character set of B,
 
1754
    or B is a string constant which can be converted into the
 
1755
    character set of A without data loss.
 
1756
    
 
1757
  If all of the above is true, then it's possible to convert
 
1758
  B into the character set of A, and then compare according
 
1759
  to the collation of A.
 
1760
  
 
1761
  For functions with more than two arguments:
 
1762
 
 
1763
    collect(A,B,C) ::= collect(collect(A,B),C)
 
1764
 
 
1765
  Since this function calls THD::change_item_tree() on the passed Item **
 
1766
  pointers, it is necessary to pass the original Item **'s, not copies.
 
1767
  Otherwise their values will not be properly restored (see BUG#20769).
 
1768
  If the items are not consecutive (eg. args[2] and args[5]), use the
 
1769
  item_sep argument, ie.
 
1770
 
 
1771
    agg_item_charsets(coll, fname, &args[2], 2, flags, 3)
 
1772
 
 
1773
*/
 
1774
 
 
1775
bool agg_item_charsets(DTCollation &coll, const char *fname,
 
1776
                       Item **args, uint nargs, uint flags, int item_sep)
 
1777
{
 
1778
  if (agg_item_collations(coll, fname, args, nargs, flags, item_sep))
 
1779
    return TRUE;
 
1780
 
 
1781
  return agg_item_set_converter(coll, fname, args, nargs, flags, item_sep);
 
1782
}
 
1783
 
 
1784
 
1752
1785
void Item_ident_for_show::make_field(Send_field *tmp_field)
1753
1786
{
1754
1787
  tmp_field->table_name= tmp_field->org_table_name= table_name;
2090
2123
}
2091
2124
 
2092
2125
 
 
2126
bool Item_field::is_null_result()
 
2127
{
 
2128
  return (null_value=result_field->is_null());
 
2129
}
 
2130
 
 
2131
 
2093
2132
bool Item_field::eq(const Item *item, bool binary_cmp) const
2094
2133
{
2095
2134
  Item *real_item= ((Item *) item)->real_item();
3082
3121
      str_value.set_charset(value.cs_info.final_character_set_of_str_value);
3083
3122
    /* Here str_value is guaranteed to be in final_character_set_of_str_value */
3084
3123
 
3085
 
    max_length= str_value.length();
 
3124
    max_length= str_value.numchars() * str_value.charset()->mbmaxlen;
3086
3125
    decimals= 0;
3087
3126
    /*
3088
3127
      str_value_ptr is returned from val_str(). It must be not alloced
5800
5839
}
5801
5840
 
5802
5841
 
 
5842
bool Item_ref::is_null_result()
 
5843
{
 
5844
  if (result_field)
 
5845
    return (null_value=result_field->is_null());
 
5846
 
 
5847
  return is_null();
 
5848
}
 
5849
 
 
5850
 
5803
5851
longlong Item_ref::val_int_result()
5804
5852
{
5805
5853
  if (result_field)
5905
5953
bool Item_ref::is_null()
5906
5954
{
5907
5955
  DBUG_ASSERT(fixed);
5908
 
  return (*ref)->is_null();
 
5956
  bool tmp=(*ref)->is_null_result();
 
5957
  null_value=(*ref)->null_value;
 
5958
  return tmp;
5909
5959
}
5910
5960
 
5911
5961