3

Hi I would like to know how to perform SQL like queries using solidity? I want to write a Dapp that records a string transaction, say, a user name each time. Also I want to be able to look up whether this username exists on the Ethereum blockchain. I know I can easily use any database system. However I want my app to be able to run on Ethereum itself. What is the correct way to do that?

3

There us no sql-like queries. To store your data you could use a mapping which is similar to a hashtable (key/value storage) or an array or just a simple variable (with set/get) : read the doc here. Every contract has its own storage which is theoretically unlimited (you should just be aware of the storage cost).

e.g of mapping use :

mapping(uint=> string) username; // a map linking each user(which is a string) with a key(which is a uint).

to store the desired username just provide its key. E.g:

uint i=1;
username[1]="yanguri"; 

so you guess it to retrieve your username use username[1].

Additional information : read about the differenece between Array an Mapping http://solidity.readthedocs.io/en/develop/introduction-to-smart-contracts.html

  • hi thanks for the information. Looks like mapping is the way to go. – Yangrui Oct 13 '16 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.