Perl DBI 自動選擇更新部分欄位的值

2021-06-21 09:19:45 字數 1105 閱讀 1598

通常,有乙個表有多個字段,有時候會只修改其中的某些字段,定義為null的字段不更新,如下updatefield函式。

#!/usr/bin/perl

use strict;

use dbi;

use constant ;

# 連線到資料庫

my $dbh = dbi->connect("dbi:sqlite:dbname=gspider.db","","",);

# 建立表

#$dbh->do("create table test(id int primary key, number, name)");

# 插入資料

#$dbh->do("insert into test values(1,6838472,'a')");

#$dbh->do("insert into test values(2,6838472,'e')");

#$dbh->do("insert into test values(3,6838472,'f')");

#updatefield(123,'e');

updatefield(null,'e');

#查詢資料

my $sql = "select * from test";

my $dbconn = $dbh->prepare($sql);

$dbconn->execute();

my $table = $dbconn->fetchall_arrayref;

my($i, $j);

for $i ( 0 .. $# ) )

print "\n";

}$dbh->commit();

$dbh->disconnect();

<>;

sub updatefield

else

my $sql = sprintf("update test set name= 's' $field where name=%s ",$fieldword,$dbh->quote($name));

$dbh->do($sql);

$dbh->commit();

}

hibernate update部分更新

hibernate update hibernate 中如果直接使用 session.update object o 會把這個表中的所有字段更新一遍。比如 view plaincopy to clipboardprint?public class teachertest public class t...

hibernate update部分更新

hibernate update hibernate 中如果直接使用 session.update object o 會把這個表中的所有字段更新一遍。比如 view plaincopy to clipboardprint?public class teachertest public class t...

xampp 更新部分或者更新全部

有時候隨著 php版本和 mysql版本的需求需要對其版本進行公升級,一下是今天總結的部分步驟,僅供參考.公升級php部分 公升級xampp xampp 安裝之後,真正的使用者資料基本上涉及下面三個地方 1.xampp htdocs 目錄 這是所有 的檔案系統。2.xampp mysql data ...