Username Remember Me?
Password   forgot password?
   
   
How to pass a variable to ths adsql query? 
Posted: 05 December 2016 05:03 PM   [ Ignore ]  
Master
RankRankRank
Total Posts:  60
Joined  2010-05-27

Dear Developer,

This is a query to get the record where the name is like Joe.
s = sdsql(database1, ‘select * from table1 where name like ‘’Joe’’’ )?

Now, I want a variable to pass this query.
var1=’Joe’
How to define this query to pass var1 into it?

any ideas?

Thanks!

Profile
 
 
Posted: 05 December 2016 06:00 PM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRank
Total Posts:  365
Joined  2008-04-26

just concatenate the query string with your specific variable using standard Matlab horizontal concat (square brackets):

>> s=sdsql(d,'select * from data where name like "Joe";')
1 by 2 set in 'test2.db':
SQL='select * from data where name like "Joe";'
>> val='Joe'

val =

Joe

>> s=sdsql(d,['select * from data where name like "' val '";'])
1 by 2 set in 'test2.db':
SQL='select * from data where name like "Joe";'
>> +s

ans 


    
[1]    'Joe'

Hope it helps

Pavel

Profile
 
 
Posted: 11 July 2017 07:12 PM   [ Ignore ]   [ # 2 ]  
Master
RankRankRank
Total Posts:  60
Joined  2010-05-27

thanks! how to delete the table using sdspl?

I use it: s=sdsql(DefLibDB, ‘drop table CFdata’)
it returns empty. it does not seem to be working.

thank you!

Profile
 
 
Posted: 14 July 2017 03:46 PM   [ Ignore ]   [ # 3 ]  
Administrator
Avatar
RankRankRankRank
Total Posts:  365
Joined  2008-04-26

Yes, to delete table, use ‘drop table table_name’ statement. It does return empty but you can test that the table is not present any more:

>> db=sddb('test.db')
perClass DB1 connections
>> s=sdsql(db,'create table data (id integer, name text);')

=

     
[]

>> insert(db,'data',{1,'Joe'5,'Bill'10,'John'12,'Betty'})

ans =

     
0

>> s=sdsql(db,'select * from data;')
4 by 2 set in 'test.db':
SQL='select * from data;'
>> +s

ans 


    
[ 1]    'Joe'  
    
[ 5]    'Bill' 
    
[10]    'John' 
    
[12]    'Betty'

>> tables(db)

ans 

    
'data'

>> s=sdsql(db,'drop table data;')

=

     
[]

>> tables(db)

ans =

     
[]

Profile
 
 
Posted: 14 July 2017 07:55 PM   [ Ignore ]   [ # 4 ]  
Master
RankRankRank
Total Posts:  60
Joined  2010-05-27

thanks!

After dropping the table, the size of the database did not change (shown in the File Explorer). E.g. original shown 8,757 kB. After deleting the only table, it still shows 8,757 kB.

Then, inserting the database, the database size doe not change. 

I hope, after dropping the table, the database size became the empty database one.

In any way, this is minor issue, I think.

Profile