0
我呼籲art_movimientosPostgreSQL的文本字段獲得'時,他們是空
CREATE TABLE public.art_movimientos
(
cmovimiento bigint NOT NULL DEFAULT nextval('art_movimientos_cmovimiento_seq'::regclass),
tipo character varying(3) NOT NULL, -- Tipos de Valores:...
fecha_mov timestamp without time zone NOT NULL,
documento integer NOT NULL,
control integer,
fecha_doc timestamp without time zone NOT NULL,
corden integer NOT NULL DEFAULT 0,
calmacen integer NOT NULL,
calmacen2 integer,
status character varying(13) NOT NULL DEFAULT 'PENDIENTE'::bpchar, -- PENDIENTE...
donado integer NOT NULL DEFAULT 0,
monto_mov numeric(11,2) NOT NULL DEFAULT 0.00,
monto_desc numeric(11,2) NOT NULL DEFAULT 0.00,
monto_total numeric(11,2) NOT NULL DEFAULT 0.00,
observacion text,
casiento integer,
crea_user character varying(25),
crea_date timestamp without time zone,
mod_user character varying(25),
mod_date timestamp without time zone,
cproveedor integer NOT NULL DEFAULT 0,
CONSTRAINT pk_cmovimiento_art_movimientos PRIMARY KEY (cmovimiento)
USING INDEX TABLESPACE sistema_index,
CONSTRAINT fk_calmacen_art_movimientos FOREIGN KEY (calmacen)
REFERENCES public.almacen (calmacen) MATCH SIMPLE
ON UPDATE RESTRICT ON DELETE RESTRICT,
CONSTRAINT ck_donado_art_movimientos CHECK (donado = ANY (ARRAY[0, 1])),
CONSTRAINT ck_monto_total_art_movimientos CHECK (monto_total > 0::numeric AND monto_total >= monto_mov),
CONSTRAINT ck_status_art_movimientos CHECK (status::text = ANY (ARRAY['PENDIENTE'::character varying, 'PROCESADO'::character varying, 'APROBADO'::character varying, 'CONTABILIZADO'::character varying]::text[])),
CONSTRAINT ck_tipo_art_movimientos CHECK (tipo::text = ANY (ARRAY['AJE'::character varying, 'AJS'::character varying, 'SI'::character varying, 'CSM'::character varying, 'COI'::character varying, 'COM'::character varying, 'DEV'::character varying, 'TRF'::character varying]::text[]))
)
WITH (
OIDS=FALSE
);
控制器中的表中獲取數據,並在數組轉換爲傳遞給類:
...
$_obs =$_POST['observacion']<>'' ? strtoupper($_POST['observacion']) : $_POST['observacion'];
....
array_push($values, $_obs);
...
$mov_dat = $mov->new_mov($values);
的DB類具有該功能,它調用另一個函數並返回結果:
public function new_mov($array){
return $mov = $this->db->procedure("insert_art_mov",$array);
}
...
public function procedure($procedure=false,$rows=false){
$response=array();
if($procedure==false){
$response="Query is Empty!";
}else{
$sql = "SELECT ".$procedure."(";
for ($i=1; $i<=count($rows); $i++){
$sql .= "$".$i.",";
}
$sql = substr($sql,0,-1);
$sql .= ")";
//echo $sql;
$res = pg_prepare($this->linkid, "my_query", $sql);
$res = @pg_execute($this->linkid, "my_query", $rows);
if($res){
while($consF=pg_fetch_assoc($res))
array_push($response,$consF[$procedure]);
}else{
array_push($response,"ERROR");
array_push($response,$this->validateOperation());
}
$sql = sprintf('DEALLOCATE "%s"',pg_escape_string("my_query"));
if(!pg_query($sql)) {
die("Can't query '$sql': " . pg_last_error());
}
return $response;
}
}
然後我執行程序在數據庫中的dure:
CREATE OR REPLACE FUNCTION public.insert_art_mov(...IN _observacion text,..)
INSERT INTO art_movimientos(tipo,fecha_mov,documento,control,fecha_doc,corden,cproveedor,calmacen,status,donado,monto_mov,monto_desc,monto_total,observacion,crea_user)
VALUES(_tipo,NOW(),_documento,_control,_fecha_doc,_corden,_cprov,_calmacen,'PENDIENTE',_donado,MONTO_MOV,_monto_desc,MONTO_TOT,_observacion,_crea_user) RETURNING cmovimiento INTO new_cmov;
但在觀察表中我看到''(簡單cuotes),我想知道爲什麼?
但我不想要NULLS或簡單的引號('')只是一個字段爲空 – JuJoGuAl
您的數據庫是否返回NULLS或空字符串?因爲在postgresql中可以存儲爲emoty字符串,但是在任何一個cas中,您都可以在前端使用相同的邏輯,因此value ='<?php echo(0!= strlen($ col_val))? 'col_val:''?>' 這將給你你需要在前端的結果 – CAllen
任何兩個,我的前端,顯示我什麼都沒有(空值),但如果有我需要做的查詢,爲選擇沒有數據的「觀察者」? SELECT * FROM art_movimientos WHERE observaciones =''? – JuJoGuAl