Index: pathauto.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.inc,v
retrieving revision 1.45.2.8
diff -u -p -r1.45.2.8 pathauto.inc
--- pathauto.inc	10 Feb 2010 22:09:18 -0000	1.45.2.8
+++ pathauto.inc	18 Feb 2010 00:21:12 -0000
@@ -353,7 +353,7 @@ function pathauto_create_alias($module, 
   $alias = pathauto_clean_alias($alias);
 
   // Enforce the maximum length.
-  $maxlength = min(variable_get('pathauto_max_length', 100), 128);
+  $maxlength = min(variable_get('pathauto_max_length', 100), _pathauto_get_schema_alias_maxlength());
   $alias = drupal_substr($alias, 0, $maxlength);
 
   // If the alias already exists, generate a new, hopefully unique, variant
@@ -568,3 +568,18 @@ function pathauto_punctuation_chars() {
 
   return $punctuation;
 }
+
+/**
+ * Fetch the maximum length of the {url_alias}.dst field from the schema.
+ *
+ * @return
+ *   An integer of the maximum url alias length allowed by the database.
+ */
+function _pathauto_get_schema_alias_maxlength() {
+  static $maxlength;
+  if (!isset($maxlength)) {
+    $schema = drupal_get_schema('url_alias');
+    $maxlength = $schema['fields']['dst']['length'];
+  }
+  return $maxlength;
+}
Index: tests/pathauto.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/tests/pathauto.test,v
retrieving revision 1.2.2.3
diff -u -p -r1.2.2.3 pathauto.test
--- tests/pathauto.test	18 Feb 2010 00:18:14 -0000	1.2.2.3
+++ tests/pathauto.test	18 Feb 2010 00:21:13 -0000
@@ -9,6 +9,31 @@
  */
 
 /**
+ * Unit tests for Pathauto functions.
+ */
+class PathautoUnitTestCase extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Pathauto unit tests',
+      'description' => 'Unit tests for Pathauto functions.',
+      'group' => 'Pathauto',
+    );
+  }
+
+  function setUp() {
+    parent::setUp('path', 'pathauto');
+    module_load_include('inc', 'pathauto');
+  }
+
+  /**
+   * Test _pathauto_get_schema_alias_maxlength().
+   */
+  function testGetSchemaAliasMaxLength() {
+    $this->assertIdentical(_pathauto_get_schema_alias_maxlength(), 128);
+  }
+}
+
+/**
  * Test basic pathauto functionality.
  */
 class PathautoFunctionalTestCase extends DrupalWebTestCase {
