Perl Learning Data Collation 1th/4 page _ Application Tips

Source: Internet
Author: User
Tags dsn prepare
The judgment of NULL value
$t {Type1id} = $ $pref {dbh}->selectrow_array ("Select Type1id from enq1 WHERE id =
3 ");
if ($t {type1id} = = 0) {
Print "Type1id is null\n";
}
==> is not a numeric term, this statement has a problem. Numeric items are private.
if (length ($t {type1id}) = = 0) {
Print "Type1id is null\n";
}
==> if NULL, this statement has a problem
If @rec contains null, the following action will have an error message
$t {Line1} = Join (", @rec);

($t {old1}, $t {new1p}, $t {new1q}) = $self->dbh->selectrow_array ("Select
Type1id,partsid,qty from enq1 WHERE id = $t {enq1_id} ");
91==> if ($t {old1} = = 0) {
--------------------------------------------------
[ERROR] [Client 127.0.0.1] Use the uninitialized value in numeric eq (=) at
./pro/mscenq1.pl line, <CONFIG> 11.,
--------------------------------------------------
How to determine if the value of an item is null (unresolved)
Fix It! First insert, put a constant (such as "B")
Origin ==>
637==> $t {NU1} = $self->dbh->selectrow_array ("Select Parts_unit from Parts_nu
where id = $t {Nuid1} ");
--------------------------------------------------
[Wed May 14 17:27:51 2008] [ERROR] [Client 127.0.0.1] Dbd::mysql::d b
Selectrow_array Failed:you have a error in your SQL syntax; Check the manual
That's corresponds to your MySQL server version for the right syntax to use near
"At line 1"/pro/mscenq1.pl line 637, <CONFIG> line, Referer:
--------------------------------------------------
To consider a situation where $T{NUID1} does not exist

Consider the situation of id=c
591==>
@{$t {p1}} = $self->dbh->selectrow_array ("select * from $t {ptable}")
WHERE id = $t {pid1} ");
--------------------------------------------------
[ERROR] [Client 127.0.0.1] Dbd::mysql::d b selectrow_array Failed:unknown
Column ' C ' WHERE clause ' at./pro/mscenq1.pl Line 591, <CONFIG> line 11.,
Referer
--------------------------------------------------
Consider the situation of $t{pid1}= ' C '
if ($#{$t {pid_list}} = = = 0 && $t {pid_list}[0] eq ' C ') {
Next
}
Copy a project's subroutine
Use strict;
Use DBI;
# Connect to the database
My (%t, $n, @fld, @rec, $pref);
Print "This is test3.pl.\n";
# Connect to the database
$ $pref {DSN} = "Dbi:mysql:host=localhost;database=cookbook";
$ $pref {DBH} = Dbi->connect ($ $pref {DSN}, "Cbuser", "Cbpass") or die "cannot"
Connect to server\n ";
$ $pref {dbh}->do ("SET NAMES UTF8");
if (!$ $pref {DBH}) {
Print "SQL read error!\n";
Exit
}
$ $pref {Table} = ' ENQ2 ';
$ $pref {oldid} = 4;
($pref) = Copy_one ($PREF);
# Close the database
$ $pref {dbh}->disconnect;
# Copy a project
Sub Copy_one {
My ($pref) = @_;
My (%t, @rec, $n);

# Take out the columns
$t {STH} = $ $pref {dbh}->prepare ("show COLUMNS from $ $pref {table}");
$t {sth}->execute;
while (@rec = $t {Sth}->fetchrow_array) {
Push (@{$t {columns}}, $rec [0]);
}
$t {sth}->finish;
# Fetching data (remember items that are NOT null)
@{$t {One}} = $ $pref {dbh}->selectrow_array ("SELECT * from $ $pref {table}")
WHERE id = $ $pref {oldid} ");

For $n (1. $#{$t {One}}) {
$t {Name} = $t {columns}[$n];
$t {Value} = $t {one}[$n];
if ($t {value}) {
$t {Value} = ' "'. $t {value}. '"';
Push (@{$t {names}}, $t {name});
Push (@{$t {values}}, $t {value});
}
}
$t {name1} = Join (', ', @{$t {names}});
$t {value1} = Join (', ', @{$t {values}});

# Insert New Item
$t {SQL} = ' INSERT into '. $ $pref {table}. '(';
$t {SQL}. = $t {name1}. ') VALUES (';
$t {SQL}. = $t {value1}. ')';

$t {do} = $ $pref {dbh}->do ($t {SQL});

# print ' do= $t {do}\n ';
return ($PREF);
}
# There may be a very simple command in MySQL to perform the above operation. The programs that have been done are here.

--------------------------------------------------------------------------------
MySQL Operation program Two
Return
--------------------------------------------------------------------------------
No ourref repeat operation.
$t {enq1_id} = $t {Q}->param ("enq1_id");
$t {Our1_new} = $self->dbh->selectrow_array ("Select Ourref from enq1 WHERE id = $t {enq1_id}");
# Get all existing QUO2 enq1id data, if there is the same not allowed to switch
# enq1 and Quo2 must be a pair of relationships
# Take out all the Ourref
$t {STH} = $self->dbh->prepare ("Select Enq1id from Quo2");
$t {sth}->execute;
while (@rec = $t {Sth}->fetchrow_array) {
$t {Our1} = $self->dbh->selectrow_array ("Select Ourref from enq1 WHERE id = $rec [0]");
Push (@{$t {Our1s}}, $t {our1});
}
$t {sth}->finish;
$t {Our1_old} = Join (', @{$t {Our1s}}});
if ($t {our1_old}!~/$t {our1_new}/) {
$t {SQL} = ' UPDATE quo2 SET enq1id = ';
$t {SQL}. = $t {enq1_id}. ' WHERE id = ';
$t {SQL}. = $t {quo2_id}. '"';
$t {do} = $self->dbh->do ("$t {SQL}");
}
Some actions to delete the contents of a table
Displays the contents of line No. 309 through 362 of the table Hull_no
Mysql> SELECT * from hull_no WHERE ID >= 309 and ID <= 362;
Delete Table Hull_no's No. 309 line to line 362 Hull_no
mysql> UPDATE hull_no SET hull_no = "" WHERE ID >= 309 and ID <= 362;
Query OK, rows affected (0.16 sec)
Rows matched:54 changed:54 warnings:0
Deletes the name of line No. 309 through 362 of the table Hull_no
mysql> UPDATE hull_no SET name = "" WHERE ID >= 309 and ID <= 362;
Query OK, rows affected (0.01 sec)
Rows matched:54 changed:54 warnings:0
Table deletes one row of actions
Mysql> show columns from Quo2;
+-----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+----------------+
| ID | Int (11) | NO | PRI | NULL | auto_increment |
| Time | Date | YES | | NULL | |
| Enq1id | Int (11) | YES | | NULL | |
| originid | Int (11) | YES | | NULL | |
| Priceid | Int (11) | YES | | NULL | |
| Paymentid | Int (11) | YES | | NULL | |
| DELIVERY | Text | YES | | NULL | |
| percent0 | Int (11) | YES | | NULL | |
| Percent | Text | YES | | NULL | |
| Price | Text | YES | | NULL | |
| Total | Int (11) | YES | | NULL | |
| Memo | Text | YES | | NULL | |
+-----------+---------+------+-----+---------+----------------+
Rows in Set (0.08 sec)
mysql> ALTER TABLE Quo2 DROP enq1id;
Query OK, 6 rows affected (0.27 sec)
Records:6 duplicates:0 warnings:0
Mysql> show columns from Quo2;
+-----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+----------------+
| ID | Int (11) | NO | PRI | NULL | auto_increment |
| Time | Date | YES | | NULL | |
| originid | Int (11) | YES | | NULL | |
| Priceid | Int (11) | YES | | NULL | |
| Paymentid | Int (11) | YES | | NULL | |
| DELIVERY | Text | YES | | NULL | |
| percent0 | Int (11) | YES | | NULL | |
| Percent | Text | YES | | NULL | |
| Price | Text | YES | | NULL | |
| Total | Int (11) | YES | | NULL | |
| Memo | Text | YES | | NULL | |
+-----------+---------+------+-----+---------+----------------+
Rows in Set (0.02 sec)
Mysql> show columns from Order1;
+-----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+----------------+
| ID | Int (11) | NO | PRI | NULL | auto_increment |
| Time | Date | YES | | NULL | |
| OrderNo | Text | YES | | NULL | |
| originid | Int (11) | YES | | NULL | |
| Priceid | Int (11) | YES | | NULL | |
| Paymentid | Int (11) | YES | | NULL | |
| DELIVERY | Text | YES | | NULL | |
| Price | Text | YES | | NULL | |
| Total | Text | YES | | NULL | |
| Memo | Text | YES | | NULL | |
+-----------+---------+------+-----+---------+----------------+
Rows in Set (0.02 sec)
mysql> ALTER TABLE order1 DROP Price;
Query OK, rows affected (0.24 sec)
Records:10 duplicates:0 warnings:0
mysql> ALTER TABLE order1 DROP total;
Query OK, rows affected (0.17 sec)
Records:10 duplicates:0 warnings:0
Mysql> show columns from Order1;
+-----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+----------------+
| ID | Int (11) | NO | PRI | NULL | auto_increment |
| Time | Date | YES | | NULL | |
| OrderNo | Text | YES | | NULL | |
| originid | Int (11) | YES | | NULL | |
| Priceid | Int (11) | YES | | NULL | |
| Paymentid | Int (11) | YES | | NULL | |
| DELIVERY | Text | YES | | NULL | |
| Memo | Text | YES | | NULL | |
+-----------+---------+------+-----+---------+----------------+
8 rows in Set (0.01 sec)
Table adds one line of action
Mysql> show columns from ENQ2;
+-----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+----------------+
| ID | Int (11) | NO | PRI | NULL | auto_increment |
| Time | Date | YES | | NULL | |
| Enq1id | Int (11) | YES | | NULL | |
| originid | Int (11) | YES | | NULL | |
| Priceid | Int (11) | YES | | NULL | |
| Paymentid | Int (11) | YES | | NULL | |
| Makerid | Int (11) | YES | | NULL | |
| DELIVERY | Text | YES | | NULL | |
| Type1id | Text | YES | | NULL | |
| Partsid | Text | YES | | NULL | |
| QTY | Text | YES | | NULL | |
| Memo | Text | YES | | NULL | |
+-----------+---------+------+-----+---------+----------------+
Rows in Set (0.06 sec)
mysql> ALTER TABLE enq2 ADD LanguageID INT after Enq1id;
Query OK, 1 row affected (0.45 sec)
Records:1 duplicates:0 warnings:0
Mysql> show columns from ENQ2;
+------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------+------+-----+---------+----------------+
| ID | Int (11) | NO | PRI | NULL | auto_increment |
| Time | Date | YES | | NULL | |
| Enq1id | Int (11) | YES | | NULL | |
| LanguageID | Int (11) | YES | | NULL | |
| originid | Int (11) | YES | | NULL | |
| Priceid | Int (11) | YES | | NULL | |
| Paymentid | Int (11) | YES | | NULL | |
| Makerid | Int (11) | YES | | NULL | |
| DELIVERY | Text | YES | | NULL | |
| Type1id | Text | YES | | NULL | |
| Partsid | Text | YES | | NULL | |
| QTY | Text | YES | | NULL | |
| Memo | Text | YES | | NULL | |
+------------+---------+------+-----+---------+----------------+
Rows in Set (0.00 sec)
Mysql> show columns from Quo1;
+----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+----------------+
| ID | Int (11) | NO | PRI | NULL | auto_increment |
| Time | Date | YES | | NULL | |
| Enq2id | Int (11) | YES | | NULL | |
| Makerref | Text | YES | | NULL | |
| Memo | Text | YES | | NULL | |
+----------+---------+------+-----+---------+----------------+
5 rows in Set (0.30 sec)
mysql> ALTER TABLE quo1 ADD price TEXT after Makerref;
Query OK, 2 rows affected (0.67 sec)
Records:2 duplicates:0 warnings:0
Mysql> show columns from Quo1;
+----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+----------------+
| ID | Int (11) | NO | PRI | NULL | auto_increment |
| Time | Date | YES | | NULL | |
| Enq2id | Int (11) | YES | | NULL | |
| Makerref | Text | YES | | NULL | |
| Price | Text | YES | | NULL | |
| Memo | Text | YES | | NULL | |
+----------+---------+------+-----+---------+----------------+
6 rows in Set (0.02 sec)
Modify the operation of a column (rename and change data definition)
Mysql> show columns from Order1;
+-----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+----------------+
| ID | Int (11) | NO | PRI | NULL | auto_increment |
| Time | Date | YES | | NULL | |
| Quo2id | Int (11) | YES | | NULL | |
| originid | Int (11) | YES | | NULL | |
| Priceid | Int (11) | YES | | NULL | |
| Paymentid | Int (11) | YES | | NULL | |
| DELIVERY | Text | YES | | NULL | |
| Price | Text | YES | | NULL | |
| Total | Text | YES | | NULL | |
| Memo | Text | YES | | NULL | |
+-----------+---------+------+-----+---------+----------------+
Rows in Set (0.16 sec)
mysql> ALTER TABLE order1 change quo2id orderno TEXT;
Query OK, 6 rows affected (0.56 sec)
Records:6 duplicates:0 warnings:0
Mysql> show columns from Order1;
+-----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+----------------+
| ID | Int (11) | NO | PRI | NULL | auto_increment |
| Time | Date | YES | | NULL | |
| OrderNo | Text | YES | | NULL | |
| originid | Int (11) | YES | | NULL | |
| Priceid | Int (11) | YES | | NULL | |
| Paymentid | Int (11) | YES | | NULL | |
| DELIVERY | Text | YES | | NULL | |
| Price | Text | YES | | NULL | |
| Total | Text | YES | | NULL | |
| Memo | Text | YES | | NULL | |
+-----------+---------+------+-----+---------+----------------+
Rows in Set (0.02 sec)

Current 1/4 page 1234 Next read the full text
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.