Студопедия

Главная страница Случайная страница

Разделы сайта

АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника






Desktop File Transfer






Here's a little app to transfer any selected file from desktop OS's to Android phone, over WIFI. The selected file can be any type of file: text or binary: image, sound, etc. On your Android run the following client code in RFO basic:

input " Save Filename", filename$, " test.jpg" input " Connect-to IP", ip$, " 192.168.1.136" input " Port number", port, 2345socket.client.connect ip$, portprint " Connected" maxclock = clock() + 30000do socket.client.read.ready flag if clock() > maxclock print " Process timed out. Ending." end endifuntil flagbyte.open W, fw, filename$socket.client.read.file fwbyte.close fwsocket.client.closeprint " Done"

A downloadable.apk file of the above app is available at https://laughton.com/basic/programs/filetransfer.apk

The desktop server is written in REBOL. There are versions of REBOL for Windows, Mac, Linux, BSD, Solaris, QNX, AIX, HP-UX, Windows CE, BEOS, Amiga, etc., so you can use this code to transfer files between a bunch different OS's and Android. Just go to https://rebol.com and download the REBOL interpreter for your OS (it's only about 1/2 meg), and paste the following code into the console (or save it in a.r file):

rebol []selected-file: request-file/onlyport-num: request-text/title/default " Port number: " " 2345" print rejoin [ " Server started on " (read join dns: // read dns: //) ": " port-num]if error? try [ port: first wait open/binary/no-wait join tcp: //: port-num] [quit]file: read/binary selected-fileinsert port fileclose portprint " Done" halt

A Windows.exe is available at https://laughton.com/basic/programs/file_transfer.exe

SQLite Databases

One of the most powerful features of RFO Basic is its built-in support for SQLite. SQLite is a small, self contained relational database system that allows you to store, retrieve, search, sort, compare, and otherwise manipulate large stores of data, very quickly and easily. SQLite is used as the main data storage system in Android devices, and is supported on just about every other modern computing platform (PC, Mac, Linux, iPhone and other mobile devices, Webkit based browser apps, Web Servers, etc.). You can easily copy and transfer entire SQLite databases of information created on your Android, and work with them on devices with different operating systems, and visa-versa.

Keep in mind that programming, and the use of computing devices in general, is ultimately about managing data, so learning to use SQLite is fundamentally useful in becoming a capable RFO Basic programmer.

Tables

In SQLite and other databases, data is stored in " tables". Tables are made up of columns of related information. A " Contacts" table, for example, may contain name, address, phone, and birthday columns. Each entry in the database can be thought of as a row containing info in each of those column fields:

name address phone birthday---- ------- -------- --------John Smith 123 Toleen Lane 555-1234 1972-02-01Paul Thompson 234 Georgetown Place 555-2345 1972-02-01Jim Persee 345 Portman Pike 555-3456 1929-07-02George Jones 456 Topforge Court 1989-12-23Tim Paulson 555-5678 2001-05-16

SQL

" SQL" statements let you work with data stored in database tables. Some SQL statements are used to create, destroy, and fill columns with data:

CREATE TABLE table_name % create a new table of informationDROP TABLE table_name % delete a tableINSERT INTO table_name VALUES (value1, value2,...) % add dataINSERT INTO Contacts VALUES ('Billy Powell', '5 Binlow Dr.', '555-6789', '1968-04-19')INSERT INTO Contacts (name, phone) VALUES ('Robert Ingram', '555-7890')

The following SQL code will create the Contacts table illustrated above:

INSERT into Contacts VALUES ('John Doe', '1 Street Lane', '555-9876', '1967-10-10'), ('John Smith', '123 Toleen Lane', '555-1234', '1972-02-01'), ('Paul Thompson', '234 Georgetown Pl.', '555-2345', '1972-02-01'), ('Jim Persee', '345 Portman Pike', '555-3456', '1929-07-02'), ('George Jones', '456 Topforge Court', '', '1989-12-23'), ('Tim Paulson', '', '555-5678', '2001-05-16')

The SELECT statement is used to retrieve information from columns in a given table:

SELECT column_name(s) FROM table_nameSELECT * FROM ContactsSELECT name, address FROM ContactsSELECT DISTINCT birthday FROM Contacts % returns no duplicate entries

To perform searches, use WHERE. Enclose search text in single quotes and use the following operators:; =, < >, >, <, > =, < =, BETWEEN, LIKE (use " %" for wildcards):

SELECT * FROM Contacts WHERE name='John Smith'SELECT * FROM Contacts WHERE name LIKE 'J%' % any name starting with " J" SELECT * FROM Contacts WHERE birthday LIKE '%72%' OR phone LIKE '%34'SELECT * FROM Contacts WHERE birthday NOT BETWEEN '1900-01-01' AND '2010-01-01'

IN lets you specify a list of data to match within a column:

SELECT * FROM Contacts WHERE phone IN ('555-1234', '555-2345')SELECT * FROM Contacts ORDER BY name % sort results alphabeticallySELECT name, birthday FROM Contacts ORDER BY birthday, name DESC

Other SQL statements:

UPDATE Contacts SET address = '643 Pine Valley Rd.' WHERE name = 'Robert Ingram' % alter or add to existing dataDELETE FROM Contacts WHERE name = 'John Smith'DELETE * FROM ContactsALTER TABLE % change the column structure of a tableCREATE INDEX % create a search keyDROP INDEX % delete a search key

There are many tutorials available online to help learn the SQL language, and SQLite, in greater depth. Take a look at https://zetcode.com/databases/sqlitetutorial for more information.

To open an SQLite database, use the following code. The file name can be anything you choose, and all the other parameters are optional. If the database file does not exist, it will be created:

db = SqlOpenDatabase(" myData.db", " 1.0", " My Data")If db = 0 Then MsgBox " Error opening database"

SQL commands should be formatted into an array. You can define your own functions to handle successful and failed SQL commands. The dbSuccess function below is very important. It demonstrates how to use a For loop to retreive and display data from an SQL SELECT command:

(to be completed...)

To execute the SQL commands, use the Sql function, with the database ID and SQL command array as parameters:

(to be completed...)

Here's a complete example that opens a database, creates a new " myData" table, inserts data into the table, and then retrieves and prints all the contents of the table:

(to be completed...)






© 2023 :: MyLektsii.ru :: Мои Лекции
Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав.
Копирование текстов разрешено только с указанием индексируемой ссылки на источник.