@@ -2,6 +2,7 @@ package CellBIS::SQL::Abstract;
22use Mojo::Base -base;
33
44use Scalar::Util qw( blessed) ;
5+ use Carp ();
56use Mojo::Util qw( trim) ;
67use CellBIS::SQL::Abstract::Util;
78use CellBIS::SQL::Abstract::Table;
@@ -62,45 +63,14 @@ sub insert {
6263sub update {
6364 my $self = shift ;
6465 my $arg_len = scalar @_ ;
65- my ($table_name , $column , $value , $clause , $type );
66- my $data = ' ' ;
67-
68- ($table_name , $column , $value , $clause ) = @_ if $arg_len == 4;
69- ($table_name , $column , $value , $clause , $type ) = @_ if $arg_len >= 5;
70-
71- my @table_field = @{$column };
72- my $field_change = ' ' ;
73- my $where_clause = ' ' ;
74-
75- if ($type && $type eq ' no-pre-st' ) {
76- my @get_value = $self -> QueryUtil-> col_with_val($column , $value );
77- $field_change = join ' , ' , @get_value ;
78-
79- if (exists $clause -> {where }) {
80- $where_clause = $self -> QueryUtil-> create_clause($clause );
81- $data = " UPDATE $table_name \n SET $field_change \n $where_clause " ;
82- }
83-
84- }
85- elsif ($type && $type eq ' pre-st' ) {
86- $field_change = join ' =?, ' , @table_field ;
87- $field_change .= ' =?' ;
88-
89- if (exists $clause -> {where }) {
90- $where_clause = $self -> QueryUtil-> create_clause($clause );
91- $data = " UPDATE $table_name \n SET $field_change \n $where_clause " ;
92- }
93- }
94- else {
95- my @get_value = $self -> QueryUtil-> col_with_val($column , $value );
96- $field_change = join ' , ' , @get_value ;
9766
98- if (exists $clause -> {where }) {
99- $where_clause = $self -> QueryUtil-> create_clause($clause );
100- $data = " UPDATE $table_name \n SET $field_change \n $where_clause " ;
67+ if ($arg_len > 2 || $arg_len >= 5) {
68+ my $method_name = ' _qUpdate_arg' . $arg_len ;
69+ if ($self -> can($method_name )) {
70+ return $self -> $method_name (@_ );
10171 }
10272 }
103- return $data ;
73+ return ' ' ;
10474}
10575
10676# For Query Delete :
@@ -158,6 +128,73 @@ sub create_table {
158128 return $result ;
159129}
160130
131+ sub _qUpdate_arg3 {
132+ my $self = shift ;
133+ my ($table_name , $col_val , $clause ) = @_ ;
134+ my $data = ' ' ;
135+
136+ Carp::croak ' $col_val is must be hashref datatype'
137+ unless ref $col_val eq " HASH" ;
138+
139+ if (exists $clause -> {where }) {
140+ my @field = map {
141+ $col_val -> {$_ } =~ qr / date|datetime|now|NOW/
142+ ? $_ . ' = ' . $col_val -> {$_ }
143+ : $_ . ' = ' . " '"
144+ . $col_val -> {$_ } . " '"
145+ } keys %{$col_val };
146+ my $field_change = join ' , ' , @field ;
147+ my $where_clause = $self -> QueryUtil-> create_clause($clause );
148+ $data = " UPDATE $table_name \n SET $field_change \n $where_clause " ;
149+ }
150+ return $data ;
151+ }
152+
153+ sub _qUpdate_arg4 {
154+ my $self = shift ;
155+ my ($table_name , $column , $value , $clause ) = @_ ;
156+ my $data = ' ' ;
157+
158+ if (exists $clause -> {where }) {
159+ my @get_value = $self -> QueryUtil-> col_with_val($column , $value );
160+ my $field_change = join ' , ' , @get_value ;
161+ my $where_clause = $self -> QueryUtil-> create_clause($clause );
162+ $data = " UPDATE $table_name \n SET $field_change \n $where_clause " ;
163+ }
164+ return $data ;
165+ }
166+
167+ sub _qUpdate_arg5 {
168+ my $self = shift ;
169+ my ($table_name , $column , $value , $clause , $type ) = @_ ;
170+ my $data = ' ' ;
171+
172+ my @table_field = @{$column };
173+ my $field_change = ' ' ;
174+ my $where_clause = ' ' ;
175+
176+ if ($type && $type eq ' no-pre-st' ) {
177+
178+ if (exists $clause -> {where }) {
179+ my @get_value = $self -> QueryUtil-> col_with_val($column , $value );
180+ $field_change = join ' , ' , @get_value ;
181+ $where_clause = $self -> QueryUtil-> create_clause($clause );
182+ $data = " UPDATE $table_name \n SET $field_change \n $where_clause " ;
183+ }
184+
185+ }
186+ else {
187+
188+ if (exists $clause -> {where }) {
189+ $field_change = join ' =?, ' , @table_field ;
190+ $field_change .= ' =?' ;
191+ $where_clause = $self -> QueryUtil-> create_clause($clause );
192+ $data = " UPDATE $table_name \n SET $field_change \n $where_clause " ;
193+ }
194+ }
195+ return $data ;
196+ }
197+
161198# For Action Query String - "select" - arg3 :
162199# ------------------------------------------------------------------------
163200sub _qSelect_arg3 {
0 commit comments